question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding springfox to spring boot project alters DateTime serialization

See original GitHub issue

After 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:open
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rgupta4-akoyacommented, Nov 15, 2018

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}

0reactions
dilipkrishcommented, Nov 28, 2018

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found