Configuring spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
has no effect on jackson based json serialization using spring 5.0 snapshot + spring boot 2.0 snapshot.
This probably requires https://jira.spring.io/browse/SPR-15247 as well.
Comment From: snicoll
has no effect on jackson based json serialization
That is a bit vague and the issue you referenced makes me think that you might be using WebFlux. If you do, there is no need to open duplicates (especially if you've found out yourself). What has no effect? Is this a general issue? Can you share a sample that demonstrates the issue?
Comment From: akiraly
I am sorry if it felt vague. Let me try to clarify.
Yes, I am trying to use spring-webflux from spring 5 (which I though was called web-reactive
maybe because the html is called like that) together with spring-boot-starter-web-reactive
from spring boot 2 (experimental).
Basically following this blog entry and this "Spring Boot Web Reactive Starter" readme. By default this setup will use jackson2 to serialize/deserialize objects to/from json.
I came to a point to using temporal types (like LocalDateTime
and ZonedDateTime
). I have noticed that the serialized forms of these by default are not ISO timestamps (I can't put an example currently but basically I ended up with an array of integers for LocalDateTime and with a single number for ZonedDateTime).
The way jackson2 serializes these types can be configured on the jackson ObjectMapper
. Usually this configuration can be handled by spring boot through spring.jackson.* properties. Which works for traditional spring MVC but apparently not for WebFlux/web-reactive.
The reason why I opened both this ticket and SPR-15247 and why I don't consider them duplicates is because I think they are related to 2 sides of the same problem.
-
The ObjectMapper is created (and not exposed for configuration) by WebFluxConfigurationSupport inside the spring framework. Which means currently nothing (neither spring-boot nor anything else) can get to those ObjectMappers. To improve this situation I have opened SPR-15247.
-
The
spring.jackson.*
properties (and they support) is provided by spring-boot. I assume (and correct me if I am wrong) just solving SPR-15247 might not makespring.jackson.*
automatically working in spring boot. That's the reason why I opened this ticket. But just this morning I have found spring-boot-web-reactive/issues/59 which seems to be about the same thing as this ticket here.
Comment From: bclozel
This is neither a bug nor a feature request - it's just about eventually catching up with the reactive support in Boot. We're working on that currently and we'll create issues/solve them as we go.
Thanks!
Comment From: reecemetcalfe
Was this issue ever addressed? I'm facing the same problems with non of the spring.jackson.serialization.* settings taking effect and sending a ZonedDateTime as {"dateTime":1616441659.159000000}.
Comment From: wilkinsona
Yes, this should work, @reecemetcalfe. Perhaps you've accidentally used @EnableWebFlux
in your application which will disable Spring Boot's auto-configuration of Spring Web Flux, including the customization of how it serializes JSON. If you don't think that's the case, please open a new issue with a minimal sample that reproduces the problem and we can take a look.
Comment From: reecemetcalfe
Thanks for the suggestion @wilkinsona but doesn't seem like that's the case - only using @SpringBootApplication
.
I'll try debug further tomorrow and raise an issue if I don't get anywhere.
Thanks
Comment From: reecemetcalfe
@wilkinsona I've debugged this to find that the default value of WRITE_DATES_AS_TIMESTAMPS = true insidethe jackson serializer.
My properties aren't taking effect it seems and I thought this was now defaulted to false? Do you have any idea where I might be going wrong?
I'm using Spring Boot 2.4.4 with Jackson Core 2.11.4
Comment From: wilkinsona
@reecemetcalfe A closed four-year-old issue isn't the right place to track your problem. Your screenshot seems to be showing Jackon's default but it's Spring Boot's JacksonAutoConfiguration
that will set WRITE_DATES_AS_TIMESTAMPS
to false
by default. If you're looking for some help and guidance, please ask a question on Stack Overflow or Gitter. If you believe you've found a bug then, as I said above, please open a new issue with a minimal sample that reproduces the problem and we can take a look.