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.

InstantDeserializer not working with offset +0800

See original GitHub issue

Hi ,

I have configured my ObjectMapper as below.

final ObjectMapper JSONMAPPER = new ObjectMapper();
JSONMAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
JSONMAPPER.registerModule(new JavaTimeModule());

working Case :

String json = "\"2020-06-24T17:00:33.585+0000\"";
Instant test = JSONMAPPER.readValue(json, Instant.class);

Not working case:

json =  "\"2020-06-24T17:00:33.585+0800\"";
test = JSONMAPPER.readValue(json, Instant.class);

Exception:

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.Instant` from String "2020-06-24T17:00:33.585+0800": Failed to deserialize java.time.Instant: (java.time.format.DateTimeParseException) Text '2020-06-24T17:00:33.585+0800' could not be parsed at index 23
 at [Source: (String)""2020-06-24T17:00:33.585+0800""; line: 1, column: 1]
	at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1676)
	at com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:932)
	at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DeserializerBase._handleDateTimeException(JSR310DeserializerBase.java:80)
	at com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer.deserialize(InstantDeserializer.java:212)
	at com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer.deserialize(InstantDeserializer.java:50)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3205)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3173)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bhushan2901commented, Jul 2, 2020

Hi @kupci , @cowtowncoder Thanks for response , sorry for delay. Yes Instant.parse(value) fails with both +0000 and +0800 , but as first works with jackson module and other not thats got me confused. as when I checked the code i see that we are replacing +0000 with Z I will try to use OffsetDateTime in my code .

1reaction
bhushan2901commented, Jun 29, 2020

i have tried this with below versions. INFO] com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.9:compile – module com.fasterxml.jackson.datatype.jsr310 [auto]

INFO] com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.1:compile – module com.fasterxml.jackson.datatype.jsr310

In both the cases same behaviour observed.

Thanks, Bhushan.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson: parse custom offset date time - Stack Overflow
The problem with optional patterns is that, when serializing, it prints all the patterns (so it will print the fraction of second twice: ......
Read more >
Standard Time Zones
The following two tables lists the time zones recognized by Calendar and Messaging Servers first in alphabetical order, and then by offset from...
Read more >
How to Handle Timezones and Synchronize Your Software ...
In this article, I'll introduce time zone issues and share some rules to ... with a -0700 offset and 18:50 in Beijing with...
Read more >
Question: How to add a timezone offset to a date?
Hi everyone, I'm running into some timezone problems: I have a process ... SSS+0800), but the offset ends up showing wrong (-0500 for...
Read more >
Specify Time Zones - MATLAB & Simulink - MathWorks
In MATLAB ®, a time zone includes the time offset from Coordinated Universal ... If you do not work with datetime values from...
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