Search in sources :

Example 11 with IonTimestamp

use of com.amazon.ion.IonTimestamp 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 12 with IonTimestamp

use of com.amazon.ion.IonTimestamp 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);
}
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 13 with IonTimestamp

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

Example 14 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project ion-java by amzn.

the class PrinterTest method testPrintingTimestamp.

// TODO annotations
// TODO field names
@Test
public void testPrintingTimestamp() throws Exception {
    IonTimestamp value = system().newNullTimestamp();
    checkNullRendering("null.timestamp", value);
    value = (IonTimestamp) oneValue("2007-05-15T18:45-00:00");
    checkRendering("2007-05-15T18:45-00:00", value);
    value = (IonTimestamp) oneValue("2007-05-15T18:45Z");
    checkRendering("2007-05-15T18:45Z", value);
    // offset +0 shortens to Z
    value = (IonTimestamp) oneValue("2007-05-15T18:45+00:00");
    checkRendering("2007-05-15T18:45Z", value);
    value = (IonTimestamp) oneValue("2007-05-15T18:45+01:12");
    checkRendering("2007-05-15T18:45+01:12", value);
    value = (IonTimestamp) oneValue("2007-05-15T18:45-10:01");
    checkRendering("2007-05-15T18:45-10:01", value);
    value.addTypeAnnotation("an");
    checkRendering("an::2007-05-15T18:45-10:01", value);
    myPrinter.setPrintTimestampAsString(true);
    checkRendering("an::\"2007-05-15T18:45-10:01\"", value);
    myPrinter.setJsonMode();
    checkRendering("" + value.getMillis(), value);
// TODO test printTimestampAsMillis
}
Also used : IonTimestamp(com.amazon.ion.IonTimestamp) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 15 with IonTimestamp

use of com.amazon.ion.IonTimestamp in project amazon-qldb-dmv-sample-java by aws-samples.

the class InsertIonTypes method main.

public static void main(final String... args) {
    final IonBlob ionBlob = Constants.SYSTEM.newBlob("hello".getBytes());
    final IonBool ionBool = Constants.SYSTEM.newBool(true);
    final IonClob ionClob = Constants.SYSTEM.newClob("{{'This is a CLOB of text.'}}".getBytes());
    final IonDecimal ionDecimal = Constants.SYSTEM.newDecimal(0.1);
    final IonFloat ionFloat = Constants.SYSTEM.newFloat(0.2);
    final IonInt ionInt = Constants.SYSTEM.newInt(1);
    final IonList ionList = Constants.SYSTEM.newList(new int[] { 1, 2 });
    final IonNull ionNull = Constants.SYSTEM.newNull();
    final IonSexp ionSexp = Constants.SYSTEM.newSexp(new int[] { 2, 3 });
    final IonString ionString = Constants.SYSTEM.newString("string");
    final IonStruct ionStruct = Constants.SYSTEM.newEmptyStruct();
    ionStruct.put("brand", Constants.SYSTEM.newString("ford"));
    final IonSymbol ionSymbol = Constants.SYSTEM.newSymbol("abc");
    final IonTimestamp ionTimestamp = Constants.SYSTEM.newTimestamp(Timestamp.now());
    final IonBlob ionNullBlob = Constants.SYSTEM.newNullBlob();
    final IonBool ionNullBool = Constants.SYSTEM.newNullBool();
    final IonClob ionNullClob = Constants.SYSTEM.newNullClob();
    final IonDecimal ionNullDecimal = Constants.SYSTEM.newNullDecimal();
    final IonFloat ionNullFloat = Constants.SYSTEM.newNullFloat();
    final IonInt ionNullInt = Constants.SYSTEM.newNullInt();
    final IonList ionNullList = Constants.SYSTEM.newNullList();
    final IonSexp ionNullSexp = Constants.SYSTEM.newNullSexp();
    final IonString ionNullString = Constants.SYSTEM.newNullString();
    final IonStruct ionNullStruct = Constants.SYSTEM.newNullStruct();
    final IonSymbol ionNullSymbol = Constants.SYSTEM.newNullSymbol();
    final IonTimestamp ionNullTimestamp = Constants.SYSTEM.newNullTimestamp();
    ConnectToLedger.getDriver().execute(txn -> {
        CreateTable.createTable(txn, TABLE_NAME);
        final Document document = new Document(Constants.SYSTEM.newString("val"));
        InsertDocument.insertDocuments(txn, TABLE_NAME, Collections.singletonList(document));
        updateRecordAndVerifyType(txn, ionBlob);
        updateRecordAndVerifyType(txn, ionBool);
        updateRecordAndVerifyType(txn, ionClob);
        updateRecordAndVerifyType(txn, ionDecimal);
        updateRecordAndVerifyType(txn, ionFloat);
        updateRecordAndVerifyType(txn, ionInt);
        updateRecordAndVerifyType(txn, ionList);
        updateRecordAndVerifyType(txn, ionNull);
        updateRecordAndVerifyType(txn, ionSexp);
        updateRecordAndVerifyType(txn, ionString);
        updateRecordAndVerifyType(txn, ionStruct);
        updateRecordAndVerifyType(txn, ionSymbol);
        updateRecordAndVerifyType(txn, ionTimestamp);
        updateRecordAndVerifyType(txn, ionNullBlob);
        updateRecordAndVerifyType(txn, ionNullBool);
        updateRecordAndVerifyType(txn, ionNullClob);
        updateRecordAndVerifyType(txn, ionNullDecimal);
        updateRecordAndVerifyType(txn, ionNullFloat);
        updateRecordAndVerifyType(txn, ionNullInt);
        updateRecordAndVerifyType(txn, ionNullList);
        updateRecordAndVerifyType(txn, ionNullSexp);
        updateRecordAndVerifyType(txn, ionNullString);
        updateRecordAndVerifyType(txn, ionNullStruct);
        updateRecordAndVerifyType(txn, ionNullSymbol);
        updateRecordAndVerifyType(txn, ionNullTimestamp);
        deleteTable(txn, TABLE_NAME);
    });
}
Also used : IonList(com.amazon.ion.IonList) IonInt(com.amazon.ion.IonInt) IonNull(com.amazon.ion.IonNull) IonBool(com.amazon.ion.IonBool) IonDecimal(com.amazon.ion.IonDecimal) IonSymbol(com.amazon.ion.IonSymbol) IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonString(com.amazon.ion.IonString) IonTimestamp(com.amazon.ion.IonTimestamp) IonBlob(com.amazon.ion.IonBlob) IonClob(com.amazon.ion.IonClob) IonFloat(com.amazon.ion.IonFloat)

Aggregations

IonTimestamp (com.amazon.ion.IonTimestamp)15 Timestamp (com.amazon.ion.Timestamp)5 Test (org.junit.Test)5 IonStruct (com.amazon.ion.IonStruct)4 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)4 Instant (java.time.Instant)4 IonInt (com.amazon.ion.IonInt)3 IonBlob (com.amazon.ion.IonBlob)2 IonBool (com.amazon.ion.IonBool)2 IonClob (com.amazon.ion.IonClob)2 IonFloat (com.amazon.ion.IonFloat)2 IonList (com.amazon.ion.IonList)2 IonSexp (com.amazon.ion.IonSexp)2 IonString (com.amazon.ion.IonString)2 IonSymbol (com.amazon.ion.IonSymbol)2 BlobTest (com.amazon.ion.BlobTest)1 ClobTest (com.amazon.ion.ClobTest)1 IntTest (com.amazon.ion.IntTest)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonException (com.amazon.ion.IonException)1