use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.
the class IonTimestampInstantSerializerTest method testSerializationWithTypeInfo02.
@Test
public void testSerializationWithTypeInfo02() throws Exception {
IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).addMixIn(Instant.class, MockObjectConfiguration.class).build();
Instant date = Instant.ofEpochSecond(123456789L, 183917322);
IonInt value = (IonInt) mapper.writeValueAsIonValue(date);
assertEquals("The value is not correct.", 123456789183L, value.longValue());
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]);
}
use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.
the class IonTimestampInstantSerializerTest method testSerializationAsString03.
@Test
public void testSerializationAsString03() throws Exception {
IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
Instant date = Instant.now();
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 testSerializationWithTypeInfo03.
@Test
public void testSerializationWithTypeInfo03() throws Exception {
IonObjectMapper mapper = newMapperBuilder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).addMixIn(Instant.class, MockObjectConfiguration.class).build();
Instant date = Instant.now();
IonTimestamp value = (IonTimestamp) mapper.writeValueAsIonValue(date);
assertEquals("The value is not correct.", TimestampUtils.toTimestamp(date, ZoneOffset.UTC), value.timestampValue());
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]);
}
use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.
the class IonTimestampOffsetDateTimeSerializerTest method testSerializationAsString02.
@Test
public void testSerializationAsString02() throws Exception {
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
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);
}
use of com.fasterxml.jackson.dataformat.ion.IonObjectMapper in project jackson-dataformats-binary by FasterXML.
the class IonTimestampOffsetDateTimeSerializerTest method testSerializationAsTimestamp02Milliseconds.
@Test
public void testSerializationAsTimestamp02Milliseconds() throws Exception {
IonObjectMapper mapper = newMapperBuilder().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS).build();
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
String value = mapper.writeValueAsString(date);
assertEquals("The value is not correct.", "123456789183", value);
}
Aggregations