use of com.amazon.ion.IonLoader in project jackson-dataformats-binary by FasterXML.
the class IonTimestampRoundTripTest method testDateRoundTrip.
@Test
public void testDateRoundTrip() {
Date date = new Date();
IonObjectMapper m = IonObjectMapper.builder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
String val = m.writeValueAsString(date);
IonLoader loader = ionSystem.newLoader();
IonDatagram dgram = loader.load(val);
IonValue ionVal = dgram.iterator().next();
Assert.assertEquals("Expected date to be serialized into an IonTimestamp", IonType.TIMESTAMP, ionVal.getType());
Date returned = m.readValue(val, Date.class);
Assert.assertEquals("Date result not the same as serialized value.", date, returned);
}
use of com.amazon.ion.IonLoader in project jackson-dataformats-binary by FasterXML.
the class SimpleIonWriteTest method ionTextCompare.
private void ionTextCompare(String generatedTextIon) {
IonLoader loader = ion.newLoader();
IonDatagram loadedDatagram = loader.load(generatedTextIon);
// the expected value is always the same {a:"value",b:42}
assertEquals(expected, loadedDatagram);
}
use of com.amazon.ion.IonLoader in project jackson-dataformats-binary by FasterXML.
the class SimpleIonWriteTest method ionBinaryCompare.
private void ionBinaryCompare(byte[] generatedBinaryIon) {
IonLoader loader = ion.newLoader();
IonDatagram loadedDatagram = loader.load(generatedBinaryIon);
// the expected value is always the same {a:"value",b:42}
assertEquals(expected, loadedDatagram);
}
use of com.amazon.ion.IonLoader in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method incrementalMultipleValuesLoadFromReader.
@Test
public void incrementalMultipleValuesLoadFromReader() throws Exception {
ResizingPipedInputStream pipe = new ResizingPipedInputStream(128);
final IonReaderBinaryIncremental reader = new IonReaderBinaryIncremental(STANDARD_READER_BUILDER, pipe);
final IonLoader loader = SYSTEM.getLoader();
byte[] bytes = toBinary("value_type::\"StringValueLong\"");
for (byte b : bytes) {
IonDatagram empty = loader.load(reader);
assertTrue(empty.isEmpty());
pipe.receive(b);
}
IonDatagram firstValue = loader.load(reader);
assertEquals(1, firstValue.size());
IonString string = (IonString) firstValue.get(0);
assertEquals("StringValueLong", string.stringValue());
assertEquals(Collections.singletonList("value_type"), Arrays.asList(string.getTypeAnnotations()));
bytes = toBinary("{foobar: \"StringValueLong\"}");
for (byte b : bytes) {
IonDatagram empty = loader.load(reader);
assertTrue(empty.isEmpty());
pipe.receive(b);
}
IonDatagram secondValue = loader.load(reader);
assertEquals(1, secondValue.size());
IonStruct struct = (IonStruct) secondValue.get(0);
string = (IonString) struct.get("foobar");
assertEquals("StringValueLong", string.stringValue());
IonDatagram empty = loader.load(reader);
assertTrue(empty.isEmpty());
reader.close();
}
use of com.amazon.ion.IonLoader in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method incrementalMultipleValuesLoadFromInputStreamFails.
@Test
public void incrementalMultipleValuesLoadFromInputStreamFails() throws Exception {
final ResizingPipedInputStream pipe = new ResizingPipedInputStream(1);
final IonLoader loader = IonSystemBuilder.standard().withReaderBuilder(STANDARD_READER_BUILDER).build().getLoader();
IonDatagram empty = loader.load(pipe);
assertTrue(empty.isEmpty());
pipe.receive(_Private_IonConstants.BINARY_VERSION_MARKER_1_0[0]);
// Because reader does not persist across load invocations, the loader must throw an exception if the reader
// had an incomplete value buffered.
thrown.expect(IonException.class);
loader.load(pipe);
}