use of com.amazon.ion.IonStruct in project ion-hive-serde by amzn.
the class IonStructToMapObjectInspector method getMap.
@Override
public Map<?, ?> getMap(final Object data) {
if (IonUtil.isIonNull((IonValue) data)) {
return null;
}
final IonStruct struct = (IonStruct) data;
// sets the initial size of the map to avoid growing as it's immutable while using the default HashMap load
// factor to maintain the same collision performance
final int size = (int) Math.ceil(struct.size() / DEFAULT_LOAD_FACTOR);
final Map<String, IonValue> map = new HashMap<>(size, DEFAULT_LOAD_FACTOR);
for (IonValue v : struct) {
map.put(v.getFieldName(), v);
}
return map;
}
use of com.amazon.ion.IonStruct in project ion-hive-serde by amzn.
the class IonStructToMapObjectInspector method getMapValueElement.
@Override
public Object getMapValueElement(final Object data, final Object key) {
if (IonUtil.isIonNull((IonValue) data)) {
return null;
}
if (key == null) {
throw new IllegalArgumentException("key cannot be null");
}
final IonStruct struct = (IonStruct) data;
final IonSymbol symbol = (IonSymbol) key;
return struct.get(symbol.stringValue());
}
use of com.amazon.ion.IonStruct 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.IonStruct in project jackson-dataformats-binary by FasterXML.
the class DataBindWriteTest method testSimpleObjectWriteIon.
@Test
public void testSimpleObjectWriteIon() throws Exception {
IonStruct struct = ion.newEmptyStruct();
IonWriter writer = ion.newWriter(struct);
writer.setFieldName("payload");
new IonObjectMapper().writeValue(writer, new MyBean());
writer.close();
IonStruct expectedStruct = ion.newEmptyStruct();
expectedStruct.put("payload", expectedMyBean.get(0).clone());
assertEquals(expectedStruct, struct);
}
use of com.amazon.ion.IonStruct in project ion-hive-serde by amzn.
the class IonStructToStructInspector method getStructFieldsDataAsList.
@Override
public List<Object> getStructFieldsDataAsList(final Object data) {
if (isIonNull((IonValue) data)) {
return null;
}
final IonStruct struct = (IonStruct) data;
List<Object> list = new ArrayList<>(struct.size());
for (IonValue v : struct) {
list.add(v);
}
return list;
}
Aggregations