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