Search in sources :

Example 61 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationAsTimestamp03Nanoseconds.

@Test
public void testSerializationAsTimestamp03Nanoseconds() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).enable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).build();
    Instant date = Instant.now();
    String value = mapper.writeValueAsString(date);
    // TODO
    assertEquals("The value is not correct.", TimestampUtils.getFractionalSeconds(date).toString(), value);
}
Also used : Instant(java.time.Instant) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 62 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo01.

/*
     **********************************************************************
     * Deserialization from values with type info
     **********************************************************************
     */
@Test
public void testDeserializationWithTypeInfo01() throws Exception {
    OffsetDateTime expected = OffsetDateTime.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("[\"" + OffsetDateTime.class.getName() + "\",123456789.183917322]", Temporal.class);
    assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) OffsetDateTime(java.time.OffsetDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 63 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo03.

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

Example 64 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo02NonUTCDefault.

@Test
public void testDeserializationWithTypeInfo02NonUTCDefault() throws Exception {
    OffsetDateTime expected = OffsetDateTime.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("[\"" + OffsetDateTime.class.getName() + "\",123456789]", Temporal.class);
    assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) OffsetDateTime(java.time.OffsetDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 65 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo03NonUTCDefault.

@Test
public void testDeserializationWithTypeInfo03NonUTCDefault() throws Exception {
    OffsetDateTime expected = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 422000000), Z1);
    IonObjectMapper m = newMapperBuilder().defaultTimeZone(TimeZone.getTimeZone(Z1)).disable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Temporal actual = m.readValue("[\"" + OffsetDateTime.class.getName() + "\", 123456789422]", Temporal.class);
    assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) OffsetDateTime(java.time.OffsetDateTime) 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