| | |
| | | @Configuration |
| | | public class JacksonConfig { |
| | | |
| | | @Primary |
| | | @Bean |
| | | public ObjectMapper getObjectMapper(Jackson2ObjectMapperBuilder builder, JacksonProperties jacksonProperties) { |
| | | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); |
| | | // 全局配置序列化返回 JSON 处理 |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | simpleModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jacksonProperties.getDateFormat()); |
| | | simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); |
| | | simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); |
| | | objectMapper.registerModule(simpleModule); |
| | | objectMapper.setTimeZone(TimeZone.getDefault()); |
| | | log.info("初始化 jackson 配置"); |
| | | return objectMapper; |
| | | } |
| | | @Primary |
| | | @Bean |
| | | public ObjectMapper getObjectMapper(Jackson2ObjectMapperBuilder builder, JacksonProperties jacksonProperties) { |
| | | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); |
| | | // 全局配置序列化返回 JSON 处理 |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | simpleModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jacksonProperties.getDateFormat()); |
| | | simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); |
| | | simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); |
| | | objectMapper.registerModule(simpleModule); |
| | | objectMapper.setTimeZone(TimeZone.getDefault()); |
| | | log.info("初始化 jackson 配置"); |
| | | return objectMapper; |
| | | } |
| | | |
| | | } |