当前位置: 首页>>代码示例>>Java>>正文


Java ObjectSerializer类代码示例

本文整理汇总了Java中com.alibaba.fastjson.serializer.ObjectSerializer的典型用法代码示例。如果您正苦于以下问题:Java ObjectSerializer类的具体用法?Java ObjectSerializer怎么用?Java ObjectSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ObjectSerializer类属于com.alibaba.fastjson.serializer包,在下文中一共展示了ObjectSerializer类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObjectWriter

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
@Override
public ObjectSerializer getObjectWriter(Class<?> clazz) {
	ObjectSerializer writer = get(clazz);
	if(writer==null){
		JSONCustom annotation = clazz.getAnnotation(JSONCustom.class);
		if (annotation != null && annotation.serializer() != Void.class) {
			ObjectSerializer os= createCustomSerializer(annotation.serializer());
			put(clazz,os);
			return os;
		}
	}
	if (writer == null) {
		if (typeCodecs != null) {
			for (Map.Entry<Class<?>, ObjectSerializer> e : typeCodecs.entrySet()) {
				if (e.getKey().isAssignableFrom(clazz)) {
					writer = e.getValue();
					put(clazz, writer);
				}
			}
		}
	}
	return super.getObjectWriter(clazz);
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:24,代码来源:SerializeConfigEx.java

示例2: test_objectWriteTest

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public void test_objectWriteTest() throws Exception {
    ObjectSerializer serializer = SerializeConfig.getGlobalInstance().getObjectWriter(Model.class);

    JSONSerializer jsonSerializer = new JSONSerializer();
    serializer.write(jsonSerializer, null, "a", Model.class, 0);

    String text = jsonSerializer.out.toString();
    assertEquals("null", text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:ObjectWriteTest.java

示例3: addSerializer

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public static final <T> void addSerializer(SerializeConfig config, Class<T> type,
		CheckedBiConsumer<T, JSONSerializer> consumer) {
	config.put(type, new ObjectSerializer() {

		@SuppressWarnings("unchecked")
		@Override
		public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
				throws IOException {
			consumer.accept((T) object, serializer);
		}

	});
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:14,代码来源:JsonFast.java

示例4: handle

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
private void handle(JSONSerializer serializer, ObjectSerializer itemSerializer, SerialContext context,
		Object object, Object fieldName, Type elementType,  Object item) throws IOException {
	serializer.println();
	if (item != null) {
		itemSerializer = serializer.getObjectWriter(item.getClass());
		SerialContext itemContext = new SerialContext(context, object, fieldName, 0, 0);
		serializer.setContext(itemContext);
		itemSerializer.write(serializer, item, fieldName, elementType, 0);
	} 
	else {
		serializer.getWriter().writeNull();
	}
}
 
开发者ID:summerDp,项目名称:dpCms,代码行数:14,代码来源:MyListSerializer.java

示例5: createJavaBeanSerializer

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public ObjectSerializer createJavaBeanSerializer(Class<?> clazz) {
	if (!Modifier.isPublic(clazz.getModifiers())) {
		MyJavaBeanSerializer bean = new MyJavaBeanSerializer(clazz);
		return bean;
	}
	return new MyJavaBeanSerializer(clazz);
}
 
开发者ID:summerDp,项目名称:dpCms,代码行数:8,代码来源:SerializeConfig.java

示例6: getObjectWriter

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
@Override
public ObjectSerializer getObjectWriter(Class<?> clazz) {
	ObjectSerializer writer = get(clazz);
	if (writer == null) {
		for (java.util.Map.Entry<Class<?>, ObjectSerializer> assignableSerializerEntry : assignableSerializerMap
				.entrySet()) {
			if (assignableSerializerEntry.getKey().isAssignableFrom(clazz)) {
				put(clazz, assignableSerializerEntry.getValue());
			}
		}
	}
	return super.getObjectWriter(clazz);
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:14,代码来源:EnhancedSerializeConfig.java

示例7: putHierarchy

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
/**
 * 对传入类型和子类都生效的序列化器
 * @param class1
 * @param nodeSer
 */
public void putHierarchy(Class<?> class1, ObjectSerializer nodeSer) {
	if (typeCodecs == null) {
		typeCodecs = new HashMap<Class<?>, ObjectSerializer>();
	}
	typeCodecs.put(class1, nodeSer);
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:12,代码来源:SerializeConfigEx.java

示例8: RuntimeSerializerInfo

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public RuntimeSerializerInfo(ObjectSerializer fieldSerializer, Class<?> runtimeFieldClass){
    super();
    this.fieldSerializer = fieldSerializer;
    this.runtimeFieldClass = runtimeFieldClass;
}
 
开发者ID:summerDp,项目名称:dpCms,代码行数:6,代码来源:MyObjectFieldSerializer.java

示例9: write

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.getWriter();
    if (object == null) {
        if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
            out.write("[]");
        } 
        else {
            out.writeNull();
        }
        return;
    }

    Type elementType = null;
    if (serializer.isEnabled(SerializerFeature.WriteClassName)) {
        if (fieldType instanceof ParameterizedType) {
            ParameterizedType param = (ParameterizedType) fieldType;
            elementType = param.getActualTypeArguments()[0];
        }
    }

    Collection<?> collection = (Collection<?>) object;

    SerialContext context = serializer.getContext();
    serializer.setContext(context, object, fieldName, 0);

    if (serializer.isEnabled(SerializerFeature.WriteClassName)) {
        if (HashSet.class == collection.getClass()) {
            out.append("Set");
        } 
        else if (TreeSet.class == collection.getClass()) {
            out.append("TreeSet");
        }
    }

    try {
        int i = 0;
        out.append('[');
        
        for (Object item : collection) {

            if (i++ != 0) {
                out.append(',');
            }

            if (item == null) {
                out.writeNull();
                continue;
            }

            Class<?> clazz = item.getClass();

            if (clazz == Integer.class) {
                out.writeInt(((Integer) item).intValue());
                continue;
            }

            if (clazz == Long.class) {
                out.writeLong(((Long) item).longValue());

                if (out.isEnabled(SerializerFeature.WriteClassName)) {
                    out.write('L');
                }
                continue;
            }

            ObjectSerializer itemSerializer = serializer.getObjectWriter(clazz);
            itemSerializer.write(serializer, item, i - 1, elementType, 0);
        }
        out.append(']');
    } 
    finally {
        serializer.setContext(context);
    }
}
 
开发者ID:summerDp,项目名称:dpCms,代码行数:75,代码来源:MyCollectionSerializer.java

示例10: putAssignableTo

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public void putAssignableTo(Class<?> clazz, ObjectSerializer objectSerializer) {
	assignableSerializerMap.put(clazz, objectSerializer);
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:4,代码来源:EnhancedSerializeConfig.java

示例11: getSerializer

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public static ObjectSerializer getSerializer() {
	return new Ser();
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:4,代码来源:PartitionKeyImpl.java

示例12: getSerializer

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
public static ObjectSerializer getSerializer(){
	return new Ser();
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:4,代码来源:PartitionTableImpl.java

示例13: addSerializeConfig

import com.alibaba.fastjson.serializer.ObjectSerializer; //导入依赖的package包/类
/**
 * 添加类型转换
 *
 * @param classz     要转换的类型
 * @param serializer 转换器
 */
public static void addSerializeConfig(Class<?> classz, ObjectSerializer serializer) {
    SerializeConfig.getGlobalInstance().put(classz, serializer);
}
 
开发者ID:treeleafj,项目名称:treeleaf,代码行数:10,代码来源:Jsoner.java


注:本文中的com.alibaba.fastjson.serializer.ObjectSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。