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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations