本文整理汇总了Java中com.fasterxml.jackson.databind.module.SimpleModule.setSerializerModifier方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleModule.setSerializerModifier方法的具体用法?Java SimpleModule.setSerializerModifier怎么用?Java SimpleModule.setSerializerModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.module.SimpleModule
的用法示例。
在下文中一共展示了SimpleModule.setSerializerModifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
@Provides
@Singleton
ObjectMapper provideObjectMapper() {
SimpleModule module = new SimpleModule();
module.setSerializerModifier(new MentorSerializerModifier());
return new ObjectMapper()
.configure(SerializationFeature.WRAP_ROOT_VALUE, false)
.configure(SerializationFeature.INDENT_OUTPUT, false)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true)
.disable(MapperFeature.AUTO_DETECT_CREATORS)
.disable(MapperFeature.AUTO_DETECT_FIELDS)
.disable(MapperFeature.AUTO_DETECT_GETTERS)
.disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
.setSerializationInclusion(Include.NON_NULL)
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"))
.registerModule(module)
;
}
示例2: getModule
import com.fasterxml.jackson.databind.module.SimpleModule; //导入方法依赖的package包/类
/**
* Gets a module wrapping this serializer as an adapter for the Jackson
* ObjectMapper.
*
* @param mapper the object mapper for default serializations
* @return a simple module to be plugged onto Jackson ObjectMapper.
*/
public static SimpleModule getModule(final ObjectMapper mapper) {
SimpleModule module = new SimpleModule();
module.setSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
if (beanDesc.getBeanClass().getAnnotation(JsonFlatten.class) != null) {
return new FlatteningSerializer(beanDesc.getBeanClass(), serializer, mapper);
}
return serializer;
}
});
return module;
}