本文整理汇总了Java中com.fasterxml.jackson.databind.ser.BeanSerializer类的典型用法代码示例。如果您正苦于以下问题:Java BeanSerializer类的具体用法?Java BeanSerializer怎么用?Java BeanSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BeanSerializer类属于com.fasterxml.jackson.databind.ser包,在下文中一共展示了BeanSerializer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeFields
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
@Override
protected void serializeFields(Object bean, final JsonGenerator gen, SerializerProvider provider) throws IOException {
if (bean instanceof ExtendedJsonWrapper) {
ExtendedJsonWrapper mixin = (ExtendedJsonWrapper) bean;
Object origin = mixin.getOrigin();
BeanSerializer serializer = (BeanSerializer) provider.findValueSerializer(origin.getClass());
new ExtendedJsonSerializer(serializer).serializeFieldsFiltered(origin, gen, provider);
Set<Entry<String, Object>> entries = mixin.getMixed().entrySet();
//gen.writeObjectField("mixedIn", mixin.getMixed());
for (Entry<String, Object> entry : entries) {
if(entry.getValue() != null){
try {
gen.writeObjectField(entry.getKey(), entry.getValue());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
} else {
super.serializeFields(bean, gen, provider);
}
}
示例2: findSerializer
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
private JsonSerializer<Object> findSerializer(Class<?> type, SerializerProvider provider, boolean eventBean)
throws JsonMappingException
{
JsonSerializer<Object> serializer = serializers.serializerFor(type);
if (serializer != null)
return serializer;
serializer = provider.findValueSerializer(type, null);
if (eventBean)
serializer = new EventBeanSerializer((BeanSerializer)serializer);
serializers = serializers.newWith(type, serializer);
return serializer;
}
示例3: modifySerializer
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
JsonSerializer<?> serializer) {
if (serializer instanceof BeanSerializer) {
return new BeanSerializerWrapper((BeanSerializer) serializer);
} else {
return serializer;
}
}
示例4: EventBeanSerializer
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
EventBeanSerializer(BeanSerializer src) {
super(src);
}
示例5: BeanSerializerWrapper
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
protected BeanSerializerWrapper(BeanSerializer src) {
super(src);
this.serializer = src;
}
示例6: ExtensibleObjectSerializer
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
public ExtensibleObjectSerializer(BeanSerializer src) {
super(src);
}
示例7: modifySerializer
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
return (serializer instanceof BeanSerializer) ? new ExtensibleObjectSerializer((BeanSerializer) serializer) : serializer;
}
示例8: DefaultJsonService
import com.fasterxml.jackson.databind.ser.BeanSerializer; //导入依赖的package包/类
/**
* Constructs and initializes a JsonService with an {@link ObjectService}.
*
* @param objectService
*/
public DefaultJsonService(final ObjectService objectService) {
idToObjDeserializer = new UntypedObjectDeserializer(null, null) {
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final Object obj = super.deserialize(p, ctxt);
if (!(obj instanceof String && ((String) obj).startsWith("object:")))
return obj;
final String id = (String) obj;
if (!objectService.contains(id)) {
throw new JsonMappingException(p, "Object does not exist");
}
final ObjectInfo info = objectService.find(id);
info.updateLastUsed();
return info.getObject();
}
};
final JsonSerializer<Object> objToIdSerializer =
new JsonSerializer<Object>()
{
@Override
public void serialize(Object value, JsonGenerator gen,
SerializerProvider serializers) throws IOException,
JsonProcessingException
{
gen.writeString(objectService.register(value, "DefaultJsonService"));
}
};
final SimpleModule objToIdModule = new SimpleModule();
objToIdModule.setSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config,
BeanDescription beanDesc, JsonSerializer<?> serializer)
{
if (Mixins.support(beanDesc.getBeanClass())) return serializer;
// If the serialized class is unknown (i.e. serialized using the general
// BeanSerializer) or should not be serialized (i.e. complicated class
// implemented interfaces such as Iterable), would be serialized as an
// ID.
if (serializer instanceof BeanSerializer) return objToIdSerializer;
if (notSerialized(beanDesc.getBeanClass())) return objToIdSerializer;
return serializer;
}
});
objToIdMapper = new ObjectMapper();
objToIdMapper.registerModule(objToIdModule);
// register Jackson MixIns to obtain better json output format for some
// specific types
Mixins.registerMixIns(objToIdMapper);
}