Search in sources :

Example 21 with IonObjectMapper

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

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo02.

@Test
public void testDeserializationWithTypeInfo02() throws Exception {
    ZonedDateTime expected = ZonedDateTime.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("[\"" + 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 22 with IonObjectMapper

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

the class IonAnnotationTypeDeserializerWithClassNameAnnotationTest method testDeserializeNonAnnotatedPayload.

@Test
public void testDeserializeNonAnnotatedPayload() throws IOException {
    IonObjectMapper mapper = constructIomWithClassNameIdResolver();
    ClassB<ClassA> newObj = mapper.readValue(ionValueWithoutAnnotation, new TypeReference<ClassB<ClassA>>() {
    });
    ClassA content = newObj.content;
    assertEquals(42, content.value);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 23 with IonObjectMapper

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

the class IonAnnotationTypeDeserializerWithClassNameAnnotationTest method testDeserializeAnnotatedPayload.

@Test
public void testDeserializeAnnotatedPayload() throws IOException {
    IonObjectMapper mapper = constructIomWithClassNameIdResolver();
    ClassB<ClassA> newObj = mapper.readValue(ionValueWithAnnotation, new TypeReference<ClassB<ClassA>>() {
    });
    ClassA content = newObj.content;
    assertEquals(42, content.value);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 24 with IonObjectMapper

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

the class PolymorphicTypeAnnotationsTest method testNativeTypeIdsDisabledReadsTypeAnnotationsSuccessfully.

@Test
public void testNativeTypeIdsDisabledReadsTypeAnnotationsSuccessfully() throws IOException {
    IonObjectMapper mapper = IonObjectMapper.builder().disable(Feature.USE_NATIVE_TYPE_ID).build();
    Container containerWithBaseClass = mapper.readValue(CONTAINER_WITH_TYPED_OBJECT, Container.class);
    Assert.assertTrue(containerWithBaseClass.objectWithType instanceof Subclass);
    Assert.assertEquals(SUBCLASS_TYPE_NAME, ((Subclass) containerWithBaseClass.objectWithType).base);
}
Also used : IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 25 with IonObjectMapper

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

the class SerializationAnnotationsTest method testNativeTypeIdsCanBeDisabledOnWrite.

@Test
public void testNativeTypeIdsCanBeDisabledOnWrite() throws Exception {
    IonObjectMapper mapper = IonObjectMapper.builderForTextualWriters().disable(IonGenerator.Feature.USE_NATIVE_TYPE_ID).build();
    IonValue subclassAsIon = mapper.writeValueAsIonValue(subclass);
    assertEqualIonValues(SUBCLASS_TYPED_AS_PROPERTY, subclassAsIon);
    BaseClass roundTripInstance = mapper.readValue(subclassAsIon, BaseClass.class);
    assertCorrectlyTypedAndFormed(subclass, roundTripInstance);
}
Also used : IonValue(com.amazon.ion.IonValue) 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