JsonFormat does not affect serialisation of Date
See original GitHub issuei use spring boot 1.3.0 (tried to 1.3.0.M5), spring-data-jpa, spring rest and mysql. i use java 8.
In my dto i have
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy", timezone="EST")
private Date birthdate;
client still continue to receive yyyy-mm-dd
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
JsonFormat deserialization fails - jackson - Stack Overflow
No, the @JsonFormat annotation is applicable for both serailization and deserailization. So in de-serailization it is used to parse the datetime string to ......
Read more >Guide to @JsonFormat in Jackson - Baeldung
We'll now use @JsonFormat to specify the format to serialize the createdDate field. Let's look at the User class updated for this change....
Read more >Annotation Type JsonFormat
General-purpose annotation used for configuring details of how values of properties are to be serialized. Unlike most other Jackson annotations, ...
Read more >Serialization Attributes - Json.NET
Attributes can be used to control how Json. ... DateTime LastModified { get; set; } // not serialized because mode is opt-in public...
Read more >JsonFormat.Feature (Jackson-annotations 2.12.0 API)
Enclosing class: JsonFormat. public static enum JsonFormat.Feature extends Enum<JsonFormat ... Only affects deserialization, has no effect on serialization.
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
if i use @Temporal(javax.persistence.TemporalType.TIMESTAMP)
that work.
This doesn’t have anything to do with Spring Boot. You’re returning a
java.sql.Date
and Jackson doesn’t appear to apply the specified formatting to it. You can see the problem with the following code that doesn’t involve Boot at all:It produces the following output:
Note that the Jackson documentation has this to say about
java.sql.Date
: