Search in sources :

Example 66 with IonObjectMapper

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

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo02.

@Test
public void testDeserializationWithTypeInfo02() throws Exception {
    OffsetDateTime expected = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 0), 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]", 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 67 with IonObjectMapper

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

the class IonAnnotationTypeDeserializerWithClassNameAnnotationTest method setupClass.

@BeforeClass
public static void setupClass() throws IOException {
    ClassA inner = new ClassA();
    inner.value = 42;
    ClassB<ClassA> outer = new ClassB<>();
    outer.content = inner;
    IonObjectMapper mapper = new IonObjectMapper();
    ionValueWithoutAnnotation = mapper.writeValueAsIonValue(outer);
    mapper = constructIomWithClassNameIdResolver();
    ionValueWithAnnotation = mapper.writeValueAsIonValue(outer);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 68 with IonObjectMapper

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

the class PolymorphicRoundtripTest method testSubclass.

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

Example 69 with IonObjectMapper

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

the class PolymorphicRoundtripTest method testTopLevelPolymorphism.

@Test
public void testTopLevelPolymorphism() throws IOException {
    resolveAllTypes = true;
    Bean original = new Bean("parent_field", new ChildBean("child_field"));
    IonObjectMapper mapper = IonObjectMapper.builder().addModule(new IonAnnotationModule()).build();
    String serialized = mapper.writeValueAsString(original);
    Object obj = mapper.readValue(serialized, Object.class);
    assertTrue(obj instanceof Bean);
    Bean deserialized = (Bean) obj;
    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 70 with IonObjectMapper

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

the class PolymorphicRoundtripTest method testPolymorphicTypeWithDate.

@Test
public void testPolymorphicTypeWithDate() throws IOException {
    resolveAllTypes = true;
    long etime = 1449191416000L;
    java.util.Date uDate = new java.util.Date(etime);
    java.sql.Date sDate = new java.sql.Date(etime);
    Bean original = new Bean("parent_field", new ChildBeanSub("child_field", "extra_field", uDate, sDate, null));
    IonObjectMapper mapper = IonObjectMapper.builder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).addModule(new IonAnnotationModule()).build();
    // roundtrip
    String serialized = mapper.writeValueAsString(original);
    Bean deserialized = mapper.readValue(serialized, Bean.class);
    ChildBeanSub deserializedSub = (ChildBeanSub) deserialized.child;
    Assert.assertEquals("Date result not the same as serialized value.", uDate, deserializedSub.uDate);
    Assert.assertEquals("Date result not the same as serialized value.", sDate, deserializedSub.sDate);
}
Also used : 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