Vadim Pakhnushev created IGNITE-23648:
-----------------------------------------

             Summary: Micronaut incorrectly deserializes Instant objects
                 Key: IGNITE-23648
                 URL: https://issues.apache.org/jira/browse/IGNITE-23648
             Project: Ignite
          Issue Type: Bug
          Components: rest
            Reporter: Vadim Pakhnushev


Jackson library serializes {{Instant}} by default as a string of the form 
{{millis.nanos}}.
Micronaut uses Jackson to deserialize JSON payload, in particular, it uses 
{{ObjectMapper.readTree}} method which reads JSON into a {{JsonNode}}. It seems 
that when doing so, Jackson treats an {{Instant}} serialized by Jackson using a 
{{double}} deserializer.
This could lead to the loss of precision.
The following test fails with the current version of Jackson:

{code:java}
@Test
void instant() throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());

    Instant instant = Instant.ofEpochSecond(1730977056L, 232784600);

    String s = mapper.writeValueAsString(instant);

    JsonNode jsonNode = mapper.readTree(s);

    Instant instant1 = mapper.treeToValue(jsonNode, Instant.class);

    assertThat(instant1.getEpochSecond(), is(instant.getEpochSecond()));
    assertThat(instant1.getNano(), is(instant.getNano())); // fails here, the 
actual value is 232784500
}
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to