本文整理匯總了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;
}