Search in sources :

Example 26 with IonObjectMapper

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

the class SerializationAnnotationsTest method testNativeTypeIdsEnabledOnWriteByDefault.

@Test
public void testNativeTypeIdsEnabledOnWriteByDefault() throws IOException {
    IonObjectMapper mapper = new IonObjectMapper();
    IonValue subclassAsIon = mapper.writeValueAsIonValue(subclass);
    assertEqualIonValues(SUBCLASS_TYPED_BY_ANNOTATION, 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)

Example 27 with IonObjectMapper

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

the class SerializationAnnotationsTest method testNativeTypeIdsDisabledStillReadsNativeTypesSuccessfully.

@Test
public void testNativeTypeIdsDisabledStillReadsNativeTypesSuccessfully() throws IOException {
    // native type ids enabled by default
    IonObjectMapper writer = new IonObjectMapper();
    IonValue subclassAsIon = writer.writeValueAsIonValue(subclass);
    assertEqualIonValues(SUBCLASS_TYPED_BY_ANNOTATION, subclassAsIon);
    IonObjectMapper reader = IonObjectMapper.builderForTextualWriters().disable(IonGenerator.Feature.USE_NATIVE_TYPE_ID).build();
    BaseClass roundTripInstance = reader.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)

Example 28 with IonObjectMapper

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

the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationWithTypeInfo03.

@Test
public void testDeserializationWithTypeInfo03() throws Exception {
    ZonedDateTime expected = ZonedDateTime.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("[\"" + ZonedDateTime.class.getName() + "\", 123456789422]", 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 29 with IonObjectMapper

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

the class IonTimestampZonedDateTimeSerializerTest method testSerializationAsTimestamp03Milliseconds.

@Test
public void testSerializationAsTimestamp03Milliseconds() throws Exception {
    IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).build();
    ZonedDateTime date = ZonedDateTime.now(Z3);
    String value = mapper.writeValueAsString(date);
    assertEquals("The value is not correct.", Long.toString(date.toInstant().toEpochMilli()), value);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 30 with IonObjectMapper

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

the class IonTimestampZonedDateTimeSerializerTest method testSerializationAsString03.

@Test
public void testSerializationAsString03() throws Exception {
    ZonedDateTime date = ZonedDateTime.now(Z3);
    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 : ZonedDateTime(java.time.ZonedDateTime) 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