Closed Tazaf closed 4 years ago
So a ZonedDateTime is not a simple pojo type object and requires special serializers registered to it. The same applies to Jackson so I'm not sure switching to it would be any different (although maybe).
I'd like the default ObjectMapper to support standard java date types so I'll go ahead and add the helpers to it.
So a ZonedDateTime is not a simple pojo type object and requires special serializers registered to it.
Oh. I was suspecting something like that.
I'd like the default ObjectMapper to support standard java date types so I'll go ahead and add the helpers to it.
Well, that's very nice of you 😃
3.10.00 Adds native default support for various Java DateTime types for the built in object mapper. All types will serialize to ISO-8601. Parsing from json will attempt various ISO variants.
Here are some tests as examples: https://github.com/Kong/unirest-java/blob/main/unirest/src/test/java/kong/unirest/JsonObjectMapperTest.java
Awesome! Very much appreciated 👍
Describe the bug Hi!
In a Spring Boot app, I'm calling an external custom API using Unirest, and I'm trying to parse the JSON response containing a serialized date (example below) into a custom class, which defines a member as a
ZonedDateTime
(example below). The response contains aparsingError
whose value is aUnirestParsingException
that have the followingdetailMessage
:Here's an example of the API JSON response:
Here's an example of the class to which I'm asking Unirest to map to:
And here's an excerpt of the method that tries to fetch that user:
Expected behavior I understand that the parsing error messages indicates that the GSON parser was expecting an object for the
createdAt
property in the JSON, since the targeted class defines aZonedDateTime
member, which is an object.But dates are stringified as strings with well defined format. I don't think that the JSON response is at fault here.
I would expect the parser to be able to see that its indeed a date and that it could parse this into a proper
ZonedDateTime
object.Am I missing something? Is this an issue with the GSON parser? Should I configure Unirest so that it uses Jackson instead?
Environmental Data
- Java Version: ``` openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing) ``` - Version: 3.4.00