这是我的对象映射器配置。我提供了我自己的对象映射器,以便覆盖Spring boot的2.0附带的对象映射器。尽管如此,我还包含了 Json 组件模块 (),以便我可以使用注释来获取自定义序列化程序。@JsonComponent
public class ObjectMapperConfigurer {
public static ObjectMapper configureObjectMapper(ObjectMapper objectMapper) {
return objectMapper.registerModules(
// First three modules can be found here. https://github.com/FasterXML/jackson-modules-java8
new Jdk8Module(), // support for other new Java 8 datatypes outside of date/time: most notably Optional, OptionalLong, OptionalDouble
new JavaTimeModule(), // support for Java 8 date/time types (specified in JSR-310 specification)
new ParameterNamesModule(), // Support for detecting constructor and factory method ("creator") parameters without having to use @JsonProperty annotation
// These two modules are provided by spring
new JsonComponentModule(), // Enables https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#boot-features-json-components
new GeoModule(), // Enables marshalling of GeoResult<T>, GeoResults<T>, and GeoPage<T>
new Hibernate5Module().enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING) // Allows jackson to gracefully handle Hibernate lazy loading,
)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
// Turn on/off some features. https://github.com/FasterXML/jackson-databind/wiki/JacksonFeatures
.enable(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS)
.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY)
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
.enable(SerializationFeature.INDENT_OUTPUT)
}
POPMUISE
慕尼黑的夜晚无繁华
相关分类