use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.
the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo04.
@Test
public void testDeserializationWithTypeInfo04() throws Exception {
Instant now = Instant.now();
OffsetDateTime expected = OffsetDateTime.ofInstant(now, UTC);
IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
Timestamp timestamp = TimestampUtils.toTimestamp(now, ZoneOffset.UTC);
Temporal actual = m.readValue("[\"" + OffsetDateTime.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
assertEquals("The value is not correct.", expected, actual);
}
use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.
the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationWithTypeInfo04NonUTCOffset.
@Test
public void testDeserializationWithTypeInfo04NonUTCOffset() throws Exception {
Instant now = Instant.now();
OffsetDateTime expected = OffsetDateTime.ofInstant(now, Z1);
IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
Timestamp timestamp = TimestampUtils.toTimestamp(now, expected.getOffset());
Temporal actual = m.readValue("[\"" + OffsetDateTime.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
assertTrue("The value should be an OffsetDateTime.", actual instanceof OffsetDateTime);
assertEquals("The value is not correct.", expected, actual);
}
use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.
the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationAsIonTimestamp04UnknownOffsetNonUTCDefault.
@Test
public void testDeserializationAsIonTimestamp04UnknownOffsetNonUTCDefault() throws Exception {
OffsetDateTime expected = OffsetDateTime.now(Z1);
Timestamp timestamp = TimestampUtils.toTimestamp(expected.toInstant(), null);
OffsetDateTime actual = READER_Z1_DEFAULT.readValue(timestamp.toString());
assertEquals("The value is not correct.", expected, actual);
}
use of com.amazon.ion.Timestamp in project ion-hive-serde by amzn.
the class TimestampSerializer method serialize.
@Override
public void serialize(final IonWriter writer, final Object data, final ObjectInspector objectInspector) throws IOException {
final PrimitiveCategory category = ((PrimitiveObjectInspector) objectInspector).getPrimitiveCategory();
switch(category) {
case DATE:
final Date date = ((DateObjectInspector) objectInspector).getPrimitiveJavaObject(data);
writer.writeTimestamp(Timestamp.forDateZ(date));
break;
case TIMESTAMP:
final java.sql.Timestamp hiveTimestamp = ((TimestampObjectInspector) objectInspector).getPrimitiveJavaObject(data);
final Timestamp value = Timestamp.forSqlTimestampZ(hiveTimestamp);
final Timestamp timestampWithOffset = value.withLocalOffset(offsetInMinutes);
writer.writeTimestamp(timestampWithOffset);
break;
default:
throw new IllegalArgumentException("Invalid object category for timestamp serializer: " + category);
}
}
use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.
the class IonTimestampZonedDateTimeDeserializerTest method testDeserializationAsIonTimestamp02.
@Test
public void testDeserializationAsIonTimestamp02() throws Exception {
ZonedDateTime expected = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), UTC);
Timestamp timestamp = TimestampUtils.toTimestamp(expected.toInstant(), expected.getOffset());
ZonedDateTime actual = READER_UTC_DEFAULT.readValue(timestamp.toString());
assertEquals("The value is not correct.", expected, actual);
}
Aggregations