use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.
the class IonGeneratorTest method testTreeWriteVerifiesOnce.
@Test
public void testTreeWriteVerifiesOnce() throws Exception {
final String FIELD = "field";
// We can test this by writing into a context where only a single object can be written
joiGenerator.writeStartObject();
joiGenerator.writeName(FIELD);
joiGenerator.writeTree(testObjectTree);
joiGenerator.writeEndObject();
// to try to trigger [dataformats-binary#248]
joiGenerator.close();
joiGenerator.close();
final IonStruct struct = (IonStruct) output.get(0);
assertThat(struct.get(FIELD), is(testObjectIon));
}
use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.
the class IonGeneratorTest method testObjectWriteVerifiesOnce.
@Test
public void testObjectWriteVerifiesOnce() throws Exception {
final String FIELD = "field";
// We can test this by writing into a context where only a single object can be written
joiGenerator.writeStartObject();
joiGenerator.writeName(FIELD);
joiGenerator.writePOJO(testObject);
joiGenerator.writeEndObject();
final IonStruct struct = (IonStruct) output.get(0);
assertThat(struct.get(FIELD), is(testObjectIon));
}
use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.
the class SimpleIonWriteTest method initializeExpectedDatagram.
@Before
public void initializeExpectedDatagram() {
IonStruct struct = ion.newEmptyStruct();
struct.add("a").newString("value");
struct.add("b").newInt(42);
struct.add("c").newNull(IonType.INT);
expected = ion.newDatagram();
expected.add(struct);
}
use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.
the class DataBindWriteTest method initializeExpectedMyBean.
@Before
public void initializeExpectedMyBean() {
expectedMyBean = ion.newDatagram();
IonStruct struct = ion.newEmptyStruct();
struct.add("a").newString("value");
struct.add("b").newInt(42);
expectedMyBean = ion.newDatagram();
expectedMyBean.add(struct);
}
use of com.amazon.ion.IonStruct in project ion-hive-serde by amzn.
the class IonHiveSerDe method deserialize.
@Override
public Object deserialize(final Writable blob) throws SerDeException {
final byte[] bytes;
final int length;
// TextFormat which produces Text
if (blob instanceof Text) {
Text text = (Text) blob;
// getBytes returns a reference to the current buffer which is only valid up to length
bytes = text.getBytes();
length = text.getLength();
} else if (blob instanceof BytesWritable) {
BytesWritable bytesWritable = (BytesWritable) blob;
// getBytes returns a reference to the current buffer which is only valid up to length
bytes = bytesWritable.getBytes();
length = bytesWritable.getLength();
} else {
throw new SerDeException("Invalid Writable instance, must be either Text or BytesWritable, was " + blob.getClass());
}
final IonSystem domFactory = ionFactory.getDomFactory();
try (final IonReader reader = ionFactory.newReader(bytes, 0, length)) {
/*
We're using an IonStruct here because:
1. We need a key-value store to carry column values
2. The top-level IonStruct as a context object carries the IonSystem which we use as a ValueFactory in
the callbacks created in PathExtractionConfig
Refer to https://github.com/amzn/ion-hive-serde/issues/61.
*/
IonStruct struct = domFactory.newEmptyStruct();
if (!serDeProperties.pathExtractorCaseSensitivity()) {
struct = new IonStructCaseInsensitiveDecorator(struct);
}
final PathExtractor<IonStruct> pathExtractor = serDeProperties.pathExtractor();
pathExtractor.match(reader, struct);
return struct;
} catch (IonException e) {
// skips if ignoring malformed
if (serDeProperties.getIgnoreMalformed()) {
return null;
}
throw e;
} catch (IOException e) {
throw new SerDeException(e);
}
}
Aggregations