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));
}
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();
}
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());
}
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);
}
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;
}
Aggregations