Search in sources :

Example 6 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationAsTimestamp01Nanoseconds.

@Test
public void testSerializationAsTimestamp01Nanoseconds() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).enable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).build();
    Instant date = Instant.ofEpochSecond(0L);
    String value = mapper.writeValueAsString(date);
    assertNotNull("The value should not be null.", value);
    assertEquals("The value is not correct.", "0.", value);
}
Also used : Instant(java.time.Instant) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 7 with IonObjectMapper

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

the class PolymorphicRoundtripTest method testSimple.

/*
    /**********************************************************************
    /* Test methods
    /**********************************************************************
     */
@Test
public void testSimple() throws IOException {
    Bean original = new Bean("parent_field", new ChildBean("child_field"));
    IonObjectMapper mapper = IonObjectMapper.builder().addModule(new IonAnnotationModule()).build();
    String serialized = mapper.writeValueAsString(original);
    Bean deserialized = mapper.readValue(serialized, Bean.class);
    assertEquals(original.field, deserialized.field);
    assertEquals(original.child.someField, deserialized.child.someField);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 8 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationAsString01.

@Test
public void testSerializationAsString01() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    Instant date = Instant.ofEpochSecond(0L);
    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 9 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationAsString02.

@Test
public void testSerializationAsString02() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    Instant date = Instant.ofEpochSecond(123456789L, 183917322);
    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 10 with IonObjectMapper

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

the class IonTimestampInstantSerializerTest method testSerializationWithTypeInfo01.

@Test
public void testSerializationWithTypeInfo01() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).enable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Instant.class, MockObjectConfiguration.class).build();
    Instant date = Instant.ofEpochSecond(123456789L, 183917322);
    IonDecimal value = (IonDecimal) mapper.writeValueAsIonValue(date);
    assertEquals("The value is not correct.", new BigDecimal("123456789.183917322"), value.bigDecimalValue());
    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 : Instant(java.time.Instant) IonDecimal(com.amazon.ion.IonDecimal) BigDecimal(java.math.BigDecimal) 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