Search in sources :

Example 1 with IonNull

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

the class IonWriterTestCase method testWriteToWithFieldName.

@Test
public void testWriteToWithFieldName() throws Exception {
    IonStruct s = system().newEmptyStruct();
    IonNull n = s.add("f").newNull();
    iw = makeWriter();
    n.writeTo(iw);
    iw.stepIn(IonType.STRUCT);
    {
        n.writeTo(iw);
        iw.setFieldName("g");
        n.writeTo(iw);
    }
    iw.stepOut();
    IonReader reader = reread();
    assertEquals(IonType.NULL, reader.next());
    assertEquals(IonType.STRUCT, reader.next());
    assertIonEquals(oneValue("{f:null, g:null}"), system().newValue(reader));
    assertNull(reader.next());
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonReader(com.amazon.ion.IonReader) IonNull(com.amazon.ion.IonNull) Test(org.junit.Test)

Example 2 with IonNull

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

the class _Private_CurriedValueFactory method newNull.

// -------------------------------------------------------------------------
public IonNull newNull() {
    IonNull v = myFactory.newNull();
    handle(v);
    return v;
}
Also used : IonNull(com.amazon.ion.IonNull)

Example 3 with IonNull

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

the class PrinterTest method testPrintingAnnotations.

// =========================================================================
// Test cases
@Test
public void testPrintingAnnotations() throws Exception {
    IonNull value = (IonNull) oneValue("an::$0::null");
    checkRendering("an::$0::null", value);
    value.addTypeAnnotation("+");
    value.addTypeAnnotation("\u0000");
    value.addTypeAnnotation("$0");
    checkRendering("an::$0::'+'::'\\0'::'$0'::null", value);
    myPrinter.setPrintSymbolAsString(true);
    checkRendering("an::$0::'+'::'\\0'::'$0'::null", value);
    myPrinter.setPrintStringAsJson(true);
    checkRendering("an::$0::'+'::'\\0'::'$0'::null", value);
    myPrinter.setPrintSymbolAsString(false);
    myPrinter.setPrintStringAsJson(false);
    myPrinter.setSkipAnnotations(true);
    checkRendering("null", value);
    myPrinter.setSkipAnnotations(false);
    IonSexp s = system().newEmptySexp();
    s.add(value);
    checkRendering("(an::$0::'+'::'\\0'::'$0'::null)", s);
    myPrinter.setPrintSymbolAsString(true);
    checkRendering("(an::$0::'+'::'\\0'::'$0'::null)", s);
    myPrinter.setPrintStringAsJson(true);
    checkRendering("(an::$0::'+'::'\\0'::'$0'::null)", s);
    value.setTypeAnnotations("boo", "boo");
    checkRendering("boo::boo::null", value);
}
Also used : IonSexp(com.amazon.ion.IonSexp) IonNull(com.amazon.ion.IonNull) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 4 with IonNull

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

the class PrinterTest method testPrintingNull.

@Test
public void testPrintingNull() throws Exception {
    IonNull value = system().newNull();
    checkNullRendering("null", value);
    value.addTypeAnnotation("an");
    checkRendering("an::null", value);
}
Also used : IonNull(com.amazon.ion.IonNull) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 5 with IonNull

use of com.amazon.ion.IonNull 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

IonNull (com.amazon.ion.IonNull)5 Test (org.junit.Test)3 BlobTest (com.amazon.ion.BlobTest)2 ClobTest (com.amazon.ion.ClobTest)2 IntTest (com.amazon.ion.IntTest)2 IonSexp (com.amazon.ion.IonSexp)2 IonStruct (com.amazon.ion.IonStruct)2 IonBlob (com.amazon.ion.IonBlob)1 IonBool (com.amazon.ion.IonBool)1 IonClob (com.amazon.ion.IonClob)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonFloat (com.amazon.ion.IonFloat)1 IonInt (com.amazon.ion.IonInt)1 IonList (com.amazon.ion.IonList)1 IonReader (com.amazon.ion.IonReader)1 IonString (com.amazon.ion.IonString)1 IonSymbol (com.amazon.ion.IonSymbol)1 IonTimestamp (com.amazon.ion.IonTimestamp)1