1

In a DTO, I can get a date string converted to a java.util.Date, using the com.fasterxml.jackson.annotation.JsonFormat annotation:

class myDTO {
     @JsonFormat(pattern="MM/dd/yyyy")
     private Date theDate;
     // accessors, etc...
}

Not so when the property is of type java.util.LocalDate...

How do I make it work?

Using jackson-databind-2.4.1

Thanks!

pointyhat
  • 568
  • 5
  • 16
  • Use `JavaTimeModule` module. Take a look at [jackson-modules-java8](https://github.com/FasterXML/jackson-modules-java8), [Jackson Serialize Instant to Nanosecond Issue](https://stackoverflow.com/questions/56345200/jackson-serialize-instant-to-nanosecond-issue), [Spring Boot Jackson date and timestamp Format](https://stackoverflow.com/questions/55256567/spring-boot-jackson-date-and-timestamp-format) – Michał Ziober Oct 28 '19 at 10:18
  • Possible duplicate of [Spring Boot Jackson date and timestamp Format](https://stackoverflow.com/questions/55256567/spring-boot-jackson-date-and-timestamp-format) – Michał Ziober Oct 28 '19 at 10:19
  • @MichałZiober, thanks. Could you provide XML config that achieves this? – pointyhat Oct 28 '19 at 22:15
  • If you use `Spring Boot` it should pick up `JavaTimeModule` module automatically if it will be on class path. So, adding dependency would be a good start. If not, you need to create custom `ObjectMapper` instance and register module manually. Take a look at [Customize the Jackson ObjectMapper](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-the-jackson-objectmapper) for an example. Which version of `Spring` do you use? – Michał Ziober Oct 28 '19 at 22:36
  • Alas, this question specifically relates to `spring-mvc` (v4. See title/tags), not `spring-boot`. Thanks for the links, but those look like they're `spring-boot`-specific. – pointyhat Oct 29 '19 at 04:37

0 Answers0