Java Code Examples for org.springframework.http.converter.json.Jackson2ObjectMapperBuilder#build()
The following examples show how to use
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder#build() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpomApplication.java From Jpom with MIT License | 6 votes |
/** * jackson 配置 * * @return mapper */ private static ObjectMapper createJackson() { Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder = Jackson2ObjectMapperBuilder.json(); jackson2ObjectMapperBuilder.simpleDateFormat(DatePattern.NORM_DATETIME_PATTERN); ObjectMapper build = jackson2ObjectMapperBuilder.build(); // 忽略空 build.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 驼峰转下划线 // build.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy()); // long to String SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); build.registerModule(simpleModule); // build.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); // build.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY); return build; }
Example 2
Source File: JacksonConfig.java From bearchoke with Apache License 2.0 | 5 votes |
@Bean public ObjectMapper objectMapper() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.featuresToDisable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); builder.featuresToEnable( SerializationFeature.WRITE_DATES_WITH_ZONE_ID, // SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, // SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, // DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT ); builder.indentOutput(true); builder.failOnEmptyBeans(false); builder.failOnUnknownProperties(false); // do not include null value in json to make object graph smaller builder.serializationInclusion(JsonInclude.Include.NON_NULL); builder.modules(new GeoJsonModule(), new JavaTimeModule(), new MoneyModule()); return builder.build(); }
Example 3
Source File: MockServerConfig.java From bearchoke with Apache License 2.0 | 5 votes |
@Bean(name = "customObjectMapper") public ObjectMapper customObjectMapper() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.featuresToDisable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); builder.featuresToEnable( SerializationFeature.WRITE_DATES_WITH_ZONE_ID, // SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, // SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, // DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT ); builder.indentOutput(true); builder.failOnEmptyBeans(false); builder.failOnUnknownProperties(false); // do not include null value in json to make object graph smaller builder.serializationInclusion(JsonInclude.Include.NON_NULL); builder.modules(new GeoJsonModule(), new JavaTimeModule(), new MoneyModule()); return builder.build(); }
Example 4
Source File: HaloConfiguration.java From halo with GNU General Public License v3.0 | 4 votes |
@Bean public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { builder.failOnEmptyBeans(false); return builder.build(); }