Search in sources :

Example 1 with IonLoader

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);
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader) Date(java.util.Date) Test(org.junit.Test)

Example 2 with IonLoader

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);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader)

Example 3 with IonLoader

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);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader)

Example 4 with IonLoader

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();
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader) Test(org.junit.Test)

Example 5 with IonLoader

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);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader) Test(org.junit.Test)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)5 IonLoader (com.amazon.ion.IonLoader)5 Test (org.junit.Test)3 IonString (com.amazon.ion.IonString)1 IonStruct (com.amazon.ion.IonStruct)1 IonValue (com.amazon.ion.IonValue)1 Date (java.util.Date)1