Search in sources :

Example 11 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampInstantDeserializerTest method testDeserializationFromStringWithNonZeroOffset02.

@Test
public void testDeserializationFromStringWithNonZeroOffset02() throws Exception {
    Instant expected = Instant.now();
    Timestamp timestamp = TimestampUtils.toTimestamp(expected, ZoneOffset.ofHours(-8));
    Instant result = READER.readValue(timestamp.toString());
    assertEquals("The value is not correct.", expected, result);
}
Also used : Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) Test(org.junit.Test)

Example 12 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampInstantDeserializerTest method testDeserializationWithTypeInfo04.

@Test
public void testDeserializationWithTypeInfo04() throws Exception {
    Instant expected = Instant.now();
    IonObjectMapper m = newMapperBuilder().addMixIn(Temporal.class, MockObjectConfiguration.class).build();
    Timestamp timestamp = TimestampUtils.toTimestamp(expected, ZoneOffset.UTC);
    Temporal actual = m.readValue("[\"" + Instant.class.getName() + "\"," + timestamp.toString() + "]", Temporal.class);
    assertTrue("The actual should be an Instant.", actual instanceof Instant);
    assertEquals("The value is not correct.", expected, actual);
}
Also used : Temporal(java.time.temporal.Temporal) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 13 with Timestamp

use of com.amazon.ion.Timestamp 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);
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 14 with Timestamp

use of com.amazon.ion.Timestamp 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);
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp) Instant(java.time.Instant) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 15 with Timestamp

use of com.amazon.ion.Timestamp in project jackson-dataformats-binary by FasterXML.

the class IonTimestampOffsetDateTimeDeserializerTest method testDeserializationAsIonTimestamp03.

@Test
public void testDeserializationAsIonTimestamp03() throws Exception {
    OffsetDateTime expected = OffsetDateTime.now(UTC);
    Timestamp timestamp = TimestampUtils.toTimestamp(expected.toInstant(), expected.getOffset());
    OffsetDateTime actual = READER_UTC_DEFAULT.readValue(timestamp.toString());
    assertEquals("The value is not correct.", expected, actual);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Timestamp(com.amazon.ion.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (com.amazon.ion.Timestamp)51 Test (org.junit.Test)38 Instant (java.time.Instant)13 OffsetDateTime (java.time.OffsetDateTime)10 ZonedDateTime (java.time.ZonedDateTime)10 IonReader (com.amazon.ion.IonReader)8 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)8 RepeatInputStream (com.amazon.ion.util.RepeatInputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 InputStream (java.io.InputStream)7 SequenceInputStream (java.io.SequenceInputStream)7 BigInteger (java.math.BigInteger)7 IonTimestamp (com.amazon.ion.IonTimestamp)6 BigDecimal (java.math.BigDecimal)5 Temporal (java.time.temporal.Temporal)5 Decimal (com.amazon.ion.Decimal)2 IonException (com.amazon.ion.IonException)2 IonWriter (com.amazon.ion.IonWriter)2 IonBlob (com.amazon.ion.IonBlob)1