-
Notifications
You must be signed in to change notification settings - Fork 122
Deserialize zone offset with or without colon #38
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
Comments
And this is for which datatype(s)? All parsing for this module uses JDK-provided parsing functionality, for that is worth. |
For Regarding JDK-provided parsing stuff, I could not find a (easy) way to build a parser that would accept both formats. Something a bit more tolerant like Jackson's Before digging deeper I thought it was better to ask here in case I missed something obvious ;-) |
Any idea ?
Then use a custom module:
Although it (seems to) work, it has the following drawbacks:
I think it could be made easier if the InstantDEserializer constructors were made public... |
I did not write this package (Nick Williams wrote it), so my understanding of design ideas (as well as Java 8 date/time limitations) is bit partial. I am ok with changing |
This seems to be fixed as part of JDK-8032051 but unfortunately the fix will be delivered only in Java 9. Would it be possible to incorporate the workaround from the comment above into |
If someone has time & itch work-arounds can be integrated. I do not have time to work on this module in near future, most likely, but can help with PRs. |
For reference, one can write such code to enable the parsing of new ObjectMapper().registerModules(
new JavaTimeModule()
.addDeserializer(OffsetDateTime.class,
new ISO8601OffsetDateTimeDeserializer()))
.disable(ADJUST_DATES_TO_CONTEXT_TIME_ZONE) public class ISO8601OffsetDateTimeDeserializer extends InstantDeserializer<OffsetDateTime> {
private static final long serialVersionUID = -237644245579626895L;
public ISO8601OffsetDateTimeDeserializer() {
super(InstantDeserializer.OFFSET_DATE_TIME,
new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
.optionalStart().appendOffset("+HH:MM", "+00:00").optionalEnd()
.optionalStart().appendOffset("+HHMM", "+0000").optionalEnd()
.optionalStart().appendOffset("+HH", "Z").optionalEnd()
.toFormatter());
}
@Override
public JsonDeserializer<OffsetDateTime> createContextual(DeserializationContext ctxt, BeanProperty property) {
// ignore context (i.e. formatting pattern that will be used for serialization)
return this;
}
} |
Hi. I hope it won't be off-topic question... Here is how I tried to configure mapper:
I also tried adding extra properties in application.yml:
But every time deserialization has to kick in, I see under debugger that features is still not disabled (com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer):
_adjustToContextTZOverride is null & context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) is true and it's not what I would expect. How to simply disable ADJUST_DATES_TO_CONTEXT_TIME_ZONE? Deserialization partially works, but result has always "Z" offset instead of precise information (lets have a "2021-04-28T19:58:40+02:00" as example input). |
@jmayday Please use other forums for usage questions -- issue tracker is specifically for issues, and not (for example) question of how to configure Jackson within specific framework. In this particular case you may want to reach out to users of framework in question (Spring? DropWizard?). |
@cowtowncoder Just going through a few 'todo' items and realized this issue was a duplicate of #131, so was fixed with @oeystein 's fix #208 . I think this can be closed. Summarizing a few pertinent quotes from above thread:
|
Is there a way to configure the module to accept zone offset expressed with and without colon ?
In other words we'd like the parser to read the following two forms:
1970-01-01T01:00:00.000+01:00
1970-01-01T01:00:00.000+0100
Note: it already accepts these two forms but ONLY if offset is zero (
+00:00
or+0000
)...The text was updated successfully, but these errors were encountered: