Search in sources :

Example 91 with IonValue

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

the class IonValueDeserializerTest method shouldBeAbleToDeserializeNullList.

@Test
public void shouldBeAbleToDeserializeNullList() throws Exception {
    IonValue ion = ion("{c:null.list}");
    IonValueData data = ION_VALUE_MAPPER.readValue(ion, IonValueData.class);
    assertEquals(1, data.getAllData().size());
    assertEquals(SYSTEM.newNullList(), data.getAllData().get("c"));
}
Also used : IonValue(com.amazon.ion.IonValue) Test(org.junit.Test)

Example 92 with IonValue

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

the class IonValueDeserializerTest method shouldBeAbleToDeserializeIncludingNullList.

@Test
public void shouldBeAbleToDeserializeIncludingNullList() throws Exception {
    IonValue ion = ion("{a:1, b:2, c:null.list}");
    IonValueData data = ION_VALUE_MAPPER.readValue(ion, IonValueData.class);
    assertEquals(3, data.getAllData().size());
    assertEquals(ion("1"), data.getAllData().get("a"));
    assertEquals(ion("2"), data.getAllData().get("b"));
    assertEquals(ion("null.list"), data.getAllData().get("c"));
}
Also used : IonValue(com.amazon.ion.IonValue) Test(org.junit.Test)

Example 93 with IonValue

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

the class DataBindReadTest method testFromIon.

/**
 * Test reading an IonValue, which also happens to not be at the top level.
 */
@Test
public void testFromIon() throws IOException {
    IonObjectMapper m = new IonObjectMapper();
    IonSystem ion = IonSystemBuilder.standard().build();
    IonValue value = ion.singleValue("{payload: {'a': bc, b : '14' }}");
    MyBean bean = m.readValue(((IonStruct) value).get("payload"), MyBean.class);
    assertEquals("bc", bean.a);
    assertEquals(14, bean.b);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) Test(org.junit.Test)

Example 94 with IonValue

use of com.amazon.ion.IonValue 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;
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) HashMap(java.util.HashMap)

Example 95 with IonValue

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

the class SerializationAnnotationsTest method testNativeTypeIdsCanBeDisabledOnWrite.

@Test
public void testNativeTypeIdsCanBeDisabledOnWrite() throws Exception {
    IonObjectMapper mapper = IonObjectMapper.builderForTextualWriters().disable(IonGenerator.Feature.USE_NATIVE_TYPE_ID).build();
    IonValue subclassAsIon = mapper.writeValueAsIonValue(subclass);
    assertEqualIonValues(SUBCLASS_TYPED_AS_PROPERTY, subclassAsIon);
    BaseClass roundTripInstance = mapper.readValue(subclassAsIon, BaseClass.class);
    assertCorrectlyTypedAndFormed(subclass, roundTripInstance);
}
Also used : IonValue(com.amazon.ion.IonValue) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Aggregations

IonValue (com.amazon.ion.IonValue)185 Test (org.junit.Test)115 IonSequence (com.amazon.ion.IonSequence)61 SymbolTable (com.amazon.ion.SymbolTable)21 IonDatagram (com.amazon.ion.IonDatagram)20 IonStruct (com.amazon.ion.IonStruct)18 IonInt (com.amazon.ion.IonInt)16 IOException (java.io.IOException)14 IonReader (com.amazon.ion.IonReader)13 IonSystem (com.amazon.ion.IonSystem)12 Result (software.amazon.qldb.Result)11 SymbolToken (com.amazon.ion.SymbolToken)10 ArrayList (java.util.ArrayList)10 IonString (com.amazon.ion.IonString)9 IonException (com.amazon.ion.IonException)7 IonType (com.amazon.ion.IonType)6 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)6 Event (com.amazon.tools.events.Event)5 com.amazon.ion.impl._Private_IonValue (com.amazon.ion.impl._Private_IonValue)4 EventType (com.amazon.tools.events.EventType)4