@Bean public JodaModule jacksonJodaModule() { JodaModule module = new JodaModule(); module.addSerializer(DateTime.class, new CustomDateTimeSerializer()); module.addDeserializer(DateTime.class, new CustomDateTimeDeserializer()); module.addSerializer(LocalDate.class, new CustomLocalDateSerializer()); module.addDeserializer(LocalDate.class, new ISO8601LocalDateDeserializer()); return module; }
/** * Convert an object to JSON byte array. * * @param object the object to convert * @return the JSON byte array * @throws IOException */ public static byte[] convertObjectToJsonBytes(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); JodaModule module = new JodaModule(); module.addSerializer(DateTime.class, new CustomDateTimeSerializer()); module.addSerializer(LocalDate.class, new CustomLocalDateSerializer()); mapper.registerModule(module); return mapper.writeValueAsBytes(object); }
@Bean public JodaModule jacksonJodaModule() { JodaModule module = new JodaModule(); DateTimeFormatterFactory formatterFactory = new DateTimeFormatterFactory(); formatterFactory.setIso(DateTimeFormat.ISO.DATE); module.addSerializer( DateTime.class, new DateTimeSerializer( new JacksonJodaFormat(formatterFactory.createDateTimeFormatter().withZoneUTC()))); return module; }