-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON-B date serialization and deserialization problem #24926
Comments
I believe you cannot mix java.util.Date (rather obsoleted type) and Java Time api. Replace the java.util.Date time you used with the java.time.LocalDate. |
Not exactly this: But it perhaps could be discussed with yasson project. |
@dmatej Thanks for you suggestion. And I agree that java.util.Date is not the perfect object for time-related conversion (I use it mainly for compatibility reason). However, in my tests, format like "2020-12-12T17:17" will be deserialized to a Date object leaving the seconds field to be zero. I failed to find what are the accepted ISO 8601 formats in JSON-B spec. I am new to Jakarta EE and glassfish, if I miss something, please tell me. Thanks! |
Looking at Yasson code, it looks like Yasson only tries to parse Date+Time (https://github.com/eclipse-ee4j/yasson/blob/master/src/main/java/org/eclipse/yasson/internal/deserializer/types/DateDeserializer.java#L47) and does respect what the spec says in https://jakarta.ee/specifications/jsonb/3.0/jakarta-jsonb-spec-3.0#java-util-date-calendar-gregoriancalendar:
This should be fixed in Yasson. I'll see if I can fix it there. |
By the way, @black-pwq , until this is fixed, you can use a Jakarta REST provider to change the default date format. If you want to change the date format only for this specific REST method, it's also possible using reflection in the provider, like this:
|
There's an issue for this already raised in Yasson project: eclipse-ee4j/yasson#487 |
I raised a pull request in Yasson: eclipse-ee4j/yasson#648 @black-pwq , @pzygielo , please review it and let me know if you think UTC should be used instead of the local timezone. |
Environment Details
Problem Description
JAX-RS runtime don't bind string like "2024-12-12" to java.util.Date. Here's example that don't work:
ISO 8601 date only string should be supported as stated in JSON-B 3.0:
The above example reports:
Steps to reproduce
Register an endpoint like the above one, and make a POST to it.
The text was updated successfully, but these errors were encountered: