Adding springfox to spring boot project alters DateTime serialization
See original GitHub issueAfter adding springfox
to my spring boot application, I have noticed that the serialization of http responses containing java.time.LocalDateTime
have changed. Here’s an export of a before an after of a snippet of JSON from one of my POJOs that is returned as part of an HTTP response to a call to a REST controller method:
"jobStateLastUpdated":"2018-11-06T10:29:57.21",
to
"jobStateLastUpdated":[2018,11,6,10,23,49,566000000],
Can I control this behavior? Why is springfox altering the serialization in this manner? I confirmed that the introduction of the Docket
class impacted the serialization.
I’m using the following dependencies in my pom.xml
file
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
<scope>compile</scope>
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Springfox Reference Documentation - GitHub Pages
Springfox works by examining an application, once, at runtime to infer API semantics based on spring configurations, class structure and various ...
Read more >Spring boot 2.04 Jackson cannot serialize LocalDateTime to ...
I have Spring boot application and LocalDateTime properties serialized as JSON array, instead of String. As I found while search on web, ...
Read more >spring-projects/spring-boot - Gitter
trying to test JSON serialization @ExtendWith(SpringExtension.class) @JsonTest public class MyobjectJsonTest { @Autowired private JacksonTester<MyObject> ...
Read more >Migrating a Spring Boot application to Java 17 – the hard way
With Spring Boot 2.5's default configuration, serialization of java.time.* types to JSON should work in 2.5 exactly as it did in 2.4 and...
Read more >Automatically Mapping DTO to Entity on Spring Boot APIs
After that we just need to import the Spring Boot project in our ... alter table exam add column created_at timestamp without time...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to reproduce this issue with a simpler project. I uploaded the source code here – its a modified set of code from a time/date serialization example project with spring boot.
https://github.com/rgupta4-akoya/sf-2764 (look at the HEAD and previous commit).
commit: bc8de0c (before enabling the swagger / springfox config)
curl http://localhost:8080/clock
{"localDate":"01::01::2016","localTime":"10:24","localDateTime":"2018-11-15T04:18:34.419Z"}
commit 48a16eb (after enabling the swagger / springfox config)
curl http://localhost:8080/clock
{"localDate":[2016,1,1],"localTime":[10,24],"localDateTime":1542255735.144000000}
@rgupta4-akoya this is probably needed because you weren’t using the same object mapper for the serialization as you were for inferring the swagger spec