The issue is that by default Jackson doesn't know how to properly serialize the Java 8 date structures (JSR 310) to JSON. As a result, it returns an entire object structure containing dayOfMonth
, dayOfWeek
, ... as you observed.
A solution would be to serialize your dates to a well-known format, like an ISO-8601 string. To do this, you first have to add support for these Java 8 types by adding the following dependency:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
After that, you should notice that your date is being serialized as an array, for example:
[2019, 2, 8, 11, 0, 0, 0, 0]
This is an array containing the year, month day of the month and so on. However, the AngularJS date filter cannot use these results yet. The proper solution would be to format them as an ISO-8601 string without timezone (considering it's a LocalDateTime
). You can do this by disabling the WRITE_DATES_AS_TIMESTAMPS
serialization feature within Jackson, by configuring the following property within application.properties:
spring.jackson.serialization.write-dates-as-timestamps=false
Now your date will beformatted as a string, for example:
"2019-02-08T11:00:00.000"
If you take a look at the documentation of the AngularJS date filter, you can see that this is properly supported:
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ).
Be aware, since you're using a LocalDateTime
, no timezone info is given, and thus, the AngularJS date filter considers this to be the local browser time, as mentioned in the same documentation:
If no timezone is specified in the string input, the time is considered to be in the local timezone.
This means that if the server timezone is different from the browser timezone, there will be issues with the given time.