`DurationSerializer` ignores format pattern if nano-second serialization enabled
See original GitHub issueIf I do this, I expect an integer number in JSON representing the number minutes:
@JsonFormat(pattern = "MINUTES")
@JsonProperty("durationInMins")
Duration duration;
But it serializes it as nanoseconds. After some debugging, I decided to add , shape = NUMBER_INT
in order to force com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase#useNanoseconds
respond false
, but it has no effect because shape is not used in the factory method I linked above.
Found a workaround: adding , without = JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
to @JsonFormat
. However, it only works if I add it to each property, adding it on class level has no effect.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Jackson Serialize Instant to Nanosecond Issue - Stack Overflow
When we are working with Java 8 Time package and Jackson good idea is to use jackson-modules-java8 project which serves many serialisers and ......
Read more >Jackson Date - Baeldung
In this tutorial, we'll serialize dates with Jackson. We'll start by serializing a simple java.util.Date, then Joda-Time, and finally, ...
Read more >SerializationFeature (jackson-databind 2.13.0 API) - FasterXML
Feature that controls whether numeric timestamp values are to be written using nanosecond timestamps (enabled) or not (disabled); if and only if datatype ......
Read more >Formatting Java Time with Spring Boot using JSON - TouK
This will change formatting of LocalDate in every endpoint of your API. We have to define: – DateTimeFormatter with our pattern. – Serializer...
Read more >Jackson JSON - Using @JsonFormat to format Date and Enum
TimeZone to use for serialization (if needed) public String timezone() ... assigned to a desired SimpleDateFormat-compatible pattern.
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 Free
Top 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
@Sam-Kruglov FINALLY found time to get back to this and hope I fixed it correctly – trivially simple change but I’m slightly worried about regression. Still, as things are tests pass and it’ll go in 2.14.0 unless something is found.
But I was wondering wrt
Instant
you mentioned has similar issues: would it be possible to show similar unit test? If so, could you please file a separate new issue for type(s) and I should be able to see if I could do more fixes before 2.14.0 release (planning to start release candidates soon).I added a modified, failing test to reproduce the issue. Unfortunately I don’t have time to pursue this further at this point, but I hope someone else can – I will make time to review PRs and so on, just not actively write a patch myself.
@kupci Not sure what you think – might be able to add in a 2.13.x patch although I am also worried that a change might be needed in construction/contextualization.