Search in sources :

Example 21 with IonSystem

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

the class DataBindReadTest method testBasicTypes.

/**
 * Test reading some basic Ion types that aren't structs/JavaBeans
 */
@Test
public void testBasicTypes() throws IOException {
    IonObjectMapper m = new IonObjectMapper();
    IonSystem ion = IonSystemBuilder.standard().build();
    assertNull(m.readValue(ion.newNull(), Object.class));
    assertEquals("foo", m.readValue(ion.newString("foo"), String.class));
}
Also used : IonSystem(com.amazon.ion.IonSystem) Test(org.junit.Test)

Example 22 with IonSystem

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

the class DataBindReadTest method testMultipleReads.

/**
 * Test reading IonValues from a reader where the values aren't at the
 * top level, making sure that no tokens are dropped and that the reader
 * is left open.
 */
@Test
public void testMultipleReads() throws IOException {
    IonObjectMapper m = new IonObjectMapper();
    IonSystem ion = IonSystemBuilder.standard().build();
    IonReader reader = ion.newReader("[foo, bar, baz]");
    assertEquals(IonType.LIST, reader.next());
    reader.stepIn();
    assertEquals("foo", m.readValue(reader, String.class));
    assertEquals("bar", m.readValue(reader, String.class));
    assertEquals("baz", m.readValue(reader, String.class));
    reader.stepOut();
    reader.close();
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonReader(com.amazon.ion.IonReader) Test(org.junit.Test)

Example 23 with IonSystem

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

the class DataBindRoundtripTest method testIonRoot.

@SuppressWarnings("rawtypes")
@Test
public void testIonRoot() throws IOException {
    String stringBean = "{a:'test',b:0.25,state:true,data:{{}}, sexp:(foo bar), nestedSexp:([foo2, foo3] (foo4 foo5)), sub:{value:'yellow'}, symbol:testSymbol, enumVal: B}";
    IonSystem system = IonSystemBuilder.standard().build();
    IonValue root = system.newLoader().load(stringBean).iterator().next();
    IonObjectMapper m = new IonObjectMapper();
    Bean bean = m.readValue(root, Bean.class);
    assertNotNull(bean);
    assertEquals(bean.a, "test");
    assertTrue(bean.b == 0.25);
    assertArrayEquals(new byte[0], bean.data);
    assertEquals(bean.state, true);
    assertNotNull(bean.sub);
    assertEquals("yellow", bean.sub.getValue());
    assertEquals("testSymbol", bean.symbol);
    assertEquals(TestEnum.B, bean.enumVal);
    assertEquals("foo", bean.sexp.get(0));
    assertEquals("bar", bean.sexp.get(1));
    assertEquals("foo2", ((List) bean.nestedSexp.get(0)).get(0));
    assertEquals("foo3", ((List) bean.nestedSexp.get(0)).get(1));
    assertEquals("foo4", ((List) bean.nestedSexp.get(1)).get(0));
    assertEquals("foo5", ((List) bean.nestedSexp.get(1)).get(1));
    IonValue subRoot = ((IonStruct) root).get("sub");
    subRoot.removeFromContainer();
    SubBean subbean = m.readValue(subRoot, SubBean.class);
    assertNotNull(subbean);
    assertEquals("yellow", subbean.getValue());
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) Test(org.junit.Test)

Example 24 with IonSystem

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

the class IonValueDeserializerTest method testWithMissingProperty.

@Test
public void testWithMissingProperty() throws IOException {
    IonSystem ionSystem = IonSystemBuilder.standard().build();
    IonObjectMapper ionObjectMapper = IonObjectMapper.builder(ionSystem).addModule(new IonValueModule()).build();
    String input1 = "{required:{}, optional:{}}";
    MyBean deserializedBean1 = ionObjectMapper.readValue(input1, MyBean.class);
    assertEquals(ionSystem.newEmptyStruct(), deserializedBean1.required);
    assertEquals(ionSystem.newEmptyStruct(), deserializedBean1.optional);
    // This deserialization should not fail with missing property
    String input2 = "{required:{}}";
    MyBean deserializedBean2 = ionObjectMapper.readValue(input2, MyBean.class);
    assertEquals(ionSystem.newEmptyStruct(), deserializedBean2.required);
    assertEquals(null, deserializedBean2.optional);
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 25 with IonSystem

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

the class _Private_IonWriterFactory method makeWriter.

/**
 * @param container must not be null.
 */
public static IonWriter makeWriter(IonContainer container) {
    IonSystem sys = container.getSystem();
    IonCatalog cat = sys.getCatalog();
    IonWriter writer = makeWriter(cat, container);
    return writer;
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonCatalog(com.amazon.ion.IonCatalog) IonWriter(com.amazon.ion.IonWriter)

Aggregations

IonSystem (com.amazon.ion.IonSystem)39 Test (org.junit.Test)27 IonValue (com.amazon.ion.IonValue)12 SymbolTable (com.amazon.ion.SymbolTable)10 IonReader (com.amazon.ion.IonReader)8 IonWriter (com.amazon.ion.IonWriter)8 IonDatagram (com.amazon.ion.IonDatagram)6 IonStruct (com.amazon.ion.IonStruct)6 IonCatalog (com.amazon.ion.IonCatalog)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IonString (com.amazon.ion.IonString)4 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)4 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)4 BinaryTest (com.amazon.ion.BinaryTest)3 IonBinaryWriter (com.amazon.ion.IonBinaryWriter)2 IonType (com.amazon.ion.IonType)2 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2