2

In my class I have date field:

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime date;

I use DataTimeFormat because I want date format like this (for my REST controller):

yyyy-MM-dd'T'HH:mm:ss.SSSZ, e.g. "2000-10-31 01:30:00.000-05:00".

But it convert in JSON to (JSON array):

"date":[2016,1,6,6,53,29,859000000]

instead of like this (JSON string):

"date":"2016-01-06 06:53:29..."

I use dependency jackson-datatype-jsr310 (because jackson-databind convert to object, like in this question).

Community
  • 1
  • 1
mkczyk
  • 2,460
  • 2
  • 25
  • 40

1 Answers1

4

Here's an excellent article on how to serialize JSON dates.

http://www.baeldung.com/jackson-serialize-dates

Option 12: Custom Serializer should be a last resort, but there are many solutions to choose from on that page.

horatius
  • 784
  • 1
  • 12
  • 30
  • 2
    This work: `@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")` instead of `@DateTimeFormat`. I get `date: "2016-01-06 06:53:29"`. Thanks. – mkczyk Jan 06 '16 at 06:31