Search in sources :

Example 36 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationWithTypeInfo02.

@Test
public void testSerializationWithTypeInfo02() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Instant.class, MockObjectConfiguration.class).build();
    Instant date = Instant.ofEpochSecond(123456789L, 183917322);
    IonInt value = (IonInt) mapper.writeValueAsIonValue(date);
    assertEquals("The value is not correct.", 123456789183L, value.longValue());
    assertEquals("The does does not contain the expected number of annotations.", 1, value.getTypeAnnotations().length);
    assertEquals("The does does not contain the expected annotation.", Instant.class.getName(), value.getTypeAnnotations()[0]);
}
Also used : IonInt(com.amazon.ion.IonInt) Instant(java.time.Instant) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 37 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationAsString03.

@Test
public void testSerializationAsString03() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    Instant date = Instant.now();
    Timestamp value = ((IonTimestamp) mapper.writeValueAsIonValue(date)).timestampValue();
    assertEquals("The value is not correct.", TimestampUtils.toTimestamp(date, ZoneOffset.UTC), value);
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 38 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationWithTypeInfo03.

@Test
public void testSerializationWithTypeInfo03() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).addMixIn(Instant.class, MockObjectConfiguration.class).build();
    Instant date = Instant.now();
    IonTimestamp value = (IonTimestamp) mapper.writeValueAsIonValue(date);
    assertEquals("The value is not correct.", TimestampUtils.toTimestamp(date, ZoneOffset.UTC), value.timestampValue());
    assertEquals("The does does not contain the expected number of annotations.", 1, value.getTypeAnnotations().length);
    assertEquals("The does does not contain the expected annotation.", Instant.class.getName(), value.getTypeAnnotations()[0]);
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp) Instant(java.time.Instant) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 39 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeSerializerTest method testSerializationAsString02.

@Test
public void testSerializationAsString02() throws Exception {
    OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
    IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    String value = mapper.writeValueAsString(date);
    assertEquals("The value is not correct.", TimestampUtils.toTimestamp(date.toInstant(), date.getOffset()).toString(), value);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 40 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeSerializerTest method testSerializationAsTimestamp02Milliseconds.

@Test
public void testSerializationAsTimestamp02Milliseconds() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).build();
    OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
    String value = mapper.writeValueAsString(date);
    assertEquals("The value is not correct.", "123456789183", value);
}
Also used : 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