Search in sources :

Example 46 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo01NonUTCDefault.

@Test
public void testDeserializationWithTypeInfo01NonUTCDefault() throws Exception {
    ZonedDateTime expected = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z1);
    IonObjectMapper m = newMapperBuilder().defaultTimeZone(TimeZone.getTimeZone(Z1)).enable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Temporal actual = m.readValue("[\"" + ZonedDateTime.class.getName() + "\",123456789.183917322]", Temporal.class);
    assertTrue("The value should be an ZonedDateTime.", actual instanceof ZonedDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 47 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo02NonUTCDefault.

@Test
public void testDeserializationWithTypeInfo02NonUTCDefault() throws Exception {
    ZonedDateTime expected = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 0), Z1);
    IonObjectMapper m = newMapperBuilder().defaultTimeZone(TimeZone.getTimeZone(Z1)).enable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Temporal actual = m.readValue("[\"" + ZonedDateTime.class.getName() + "\",123456789]", Temporal.class);
    assertTrue("The value should be an ZonedDateTime.", actual instanceof ZonedDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 48 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo04.

@Test
public void testDeserializationWithTypeInfo04() throws Exception {
    Instant now = Instant.now();
    ZonedDateTime expected = ZonedDateTime.ofInstant(now, UTC);
    IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Timestamp timestamp = TimestampUtils.toTimestamp(now, ZoneOffset.UTC);
    Temporal actual = m.readValue("[\"" + ZonedDateTime.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
    assertTrue("The value should be an ZonedDateTime.", actual instanceof ZonedDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 49 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo01.

/*
     **********************************************************************
     * Deserialization from values with type info
     **********************************************************************
     */
@Test
public void testDeserializationWithTypeInfo01() throws Exception {
    ZonedDateTime expected = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), UTC);
    IonObjectMapper m = newMapperBuilder().enable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Temporal actual = m.readValue("[\"" + ZonedDateTime.class.getName() + "\",123456789.183917322]", Temporal.class);
    assertTrue("The value should be an ZonedDateTime.", actual instanceof ZonedDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 50 with IonObjectMapper

use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo04NonUTCOffset.

@Test
public void testDeserializationWithTypeInfo04NonUTCOffset() throws Exception {
    Instant now = Instant.now();
    ZonedDateTime expected = ZonedDateTime.ofInstant(now, Z1);
    IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Timestamp timestamp = TimestampUtils.toTimestamp(now, expected.getOffset());
    Temporal actual = m.readValue("[\"" + ZonedDateTime.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
    assertTrue("The value should be an ZonedDateTime.", actual instanceof ZonedDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Aggregations

IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)72 Test (org.junit.Test)70 Temporal (java.time.temporal.Temporal)24 Instant (java.time.Instant)20 OffsetDateTime (java.time.OffsetDateTime)20 ZonedDateTime (java.time.ZonedDateTime)20 Timestamp (com.amazon.ion.Timestamp)8 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonValue (com.amazon.ion.IonValue)4 IonDecimal (com.amazon.ion.IonDecimal)1 IonInt (com.amazon.ion.IonInt)1 IonSystem (com.amazon.ion.IonSystem)1 DatabindException (com.fasterxml.jackson.databind.DatabindException)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BeforeClass (org.junit.BeforeClass)1 Result (software.amazon.qldb.Result)1