Search in sources :

Example 41 with IonDatagram

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

the class DataBindWriteTest method testIntArrayWriteBinary.

@Test
public void testIntArrayWriteBinary() throws Exception {
    byte[] data = _writeAsBytes(new int[] { 1, 2, 3 });
    assertNotNull(data);
    IonDatagram loadedDatagram = ion.newLoader().load(data);
    assertEquals(expectedArray, loadedDatagram);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 42 with IonDatagram

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

the class DataBindWriteTest method testIntArrayWriteText.

@Test
public void testIntArrayWriteText() throws Exception {
    IonObjectMapper m = new IonObjectMapper(IonFactory.forTextualWriters());
    IonDatagram loadedDatagram = ion.newLoader().load(m.writeValueAsString(new int[] { 1, 2, 3 }));
    assertEquals(expectedArray, loadedDatagram);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 43 with IonDatagram

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

the class DataBindWriteTest method testSimpleObjectWriteText.

/*
    /**********************************************************************
    /* Test methods
    /**********************************************************************
     */
@Test
public void testSimpleObjectWriteText() throws Exception {
    IonObjectMapper m = IonObjectMapper.builderForTextualWriters().build();
    // now parse it using IonLoader and compare
    IonDatagram loadedDatagram = ion.newLoader().load(m.writeValueAsString(new MyBean()));
    assertEquals(expectedMyBean, loadedDatagram);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 44 with IonDatagram

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

the class IonTimestampRoundTripTest method testDateRoundTrip.

@Test
public void testDateRoundTrip() {
    Date date = new Date();
    IonObjectMapper m = IonObjectMapper.builder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    String val = m.writeValueAsString(date);
    IonLoader loader = ionSystem.newLoader();
    IonDatagram dgram = loader.load(val);
    IonValue ionVal = dgram.iterator().next();
    Assert.assertEquals("Expected date to be serialized into an IonTimestamp", IonType.TIMESTAMP, ionVal.getType());
    Date returned = m.readValue(val, Date.class);
    Assert.assertEquals("Date result not the same as serialized value.", date, returned);
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader) Date(java.util.Date) Test(org.junit.Test)

Example 45 with IonDatagram

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

the class IonObjectMapper method writeValueAsIonValue.

/**
 * Method that can be used to map any Java value to an IonValue.
 */
public IonValue writeValueAsIonValue(Object value) throws IOException {
    // 04-Jan-2017, tatu: Bit of incompatiblity wrt 2.x handling: should this result in
    // Java `null`, or Ion null marker? For now, choose latter
    /*        
        if (value == null) {
            return null;
        }
        */
    IonFactory f = tokenStreamFactory();
    IonDatagram container = f._system.newDatagram();
    try (IonWriter writer = f._system.newWriter(container)) {
        writeValue(writer, value);
        IonValue result = container.get(0);
        result.removeFromContainer();
        return result;
    }
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) IonWriter(com.amazon.ion.IonWriter)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2