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!

5
  • Use JavaTimeModule module. Take a look at jackson-modules-java8, Jackson Serialize Instant to Nanosecond Issue, Spring Boot Jackson date and timestamp Format Commented Oct 28, 2019 at 10:18
  • Possible duplicate of Spring Boot Jackson date and timestamp Format Commented Oct 28, 2019 at 10:19
  • @MichałZiober, thanks. Could you provide XML config that achieves this? Commented Oct 28, 2019 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 for an example. Which version of Spring do you use? Commented Oct 28, 2019 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. Commented Oct 29, 2019 at 4:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.