question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deserialize zone offset with or without colon

See original GitHub issue

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)…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jmaydaycommented, Jul 12, 2019

Hi. I hope it won’t be off-topic question… I have some issue trying to disable ADJUST_DATES_TO_CONTEXT_TIME_ZONE feature in Spring application.

Here is how I tried to configure mapper:

  @Bean
  @Primary
  public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    ObjectMapper objectMapper = builder.createXmlMapper(false).build();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
    return objectMapper;
  }

I also tried adding extra properties in application.yml:

spring:
  jackson:
    deserialization:
      adjust-dates-to-context-time-zone: false
      ADJUST_DATES_TO_CONTEXT_TIME_ZONE: false

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):

    protected boolean shouldAdjustToContextTimezone(DeserializationContext context) {
        return (_adjustToContextTZOverride != null) ? _adjustToContextTZOverride :
                context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
    }

_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).

1reaction
brenuartcommented, Feb 26, 2018

For OffsetDateTime and ZonedDateTime

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 StdDateFormat for java.util.Date

Before digging deeper I thought it was better to ask here in case I missed something obvious 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 8 Date and Time: parse ISO 8601 string without colon in ...
@JonSkeet - ISO 8601 allows offsets without a colon in the basic format, and offsets with a colon in the extended format. However,...
Read more >
StdDateFormat (jackson-databind 2.11.0 API) - FasterXML
Accessor for checking whether this instance would include colon within timezone serialization or not: if {code true}, timezone offset is serialized like -06:00 ......
Read more >
Stand-Alone JSON Serialization using ... - Microsoft Learn
NET objects into JSON data and to deserialize such data back into instances ... If there is no namespace the colon can be...
Read more >
DateTimeFormatter (Java SE 12 & JDK 12 ) - Oracle Help Center
Offset Z: This formats the offset based on the number of pattern letters. One, two or three letters outputs the hour and minute,...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
Instead write just 1 without a zero and use at least one digit after a decimal point: JSON.parse('{"foo": 1}'); JSON.parse('{"foo": 1.0}');
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found