use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class PrinterTest method testJsonEscapeNonBmp.
@Test
public void testJsonEscapeNonBmp() throws Exception {
final String literal = new StringBuilder().append("'''").append('\uDAF7').append('\uDE56').append("'''").toString();
final byte[] utf8Bytes = _Private_Utils.utf8(literal);
final IonDatagram dg = loader().load(utf8Bytes);
final StringBuilder out = new StringBuilder();
final Printer json = new Printer();
json.setJsonMode();
json.print(dg.get(0), out);
assertEquals("\"\\uDAF7\\uDE56\"".toLowerCase(), out.toString().toLowerCase());
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class ReaderDomCopyTest method iterateIon.
void iterateIon(File myTestFile) throws IOException {
IonDatagram dg = system().getLoader().load(myTestFile);
IonReader reader = system().newReader(dg);
for (int i = 0; reader.next() != null; i++) {
IonValue actual = system().newValue(reader);
assertIonEquals(dg.get(i), actual);
}
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class MiscStreamingTest method testBinaryAnnotation.
@Test
public void testBinaryAnnotation() throws Exception {
String s = "item_view::{item_id:\"B00096H8Q4\",marketplace_id:2," + "product:{item_name:[" + "{value:'''Method 24CT Leather Wipes''',lang:EN_CA}," + "{value:'''Method 24CT Chiffons de Cuir''',lang:FR_CA}]," + "list_price:{value:18.23,unit:EUR},}" + ",index_suppressed:true," + "offline_store_only:true,version:2,}";
IonSystem sys = system();
IonDatagram dg = sys.getLoader().load(s);
IonValue v = dg.get(0);
IonType t = v.getType();
assertSame("should be a struct", t, IonType.STRUCT);
// first make sure the ion tree got it right
assertTrue(v.hasTypeAnnotation("item_view"));
String[] ann = v.getTypeAnnotations();
assertTrue(ann.length == 1 && ann[0].equals("item_view"));
// now take the string and get a text iterator and
// make sure it got the annotation right
IonReader it = system().newReader(s);
t = it.next();
assertSame("should be a struct", t, IonType.STRUCT);
ann = it.getTypeAnnotations();
assertTrue(ann.length == 1 && ann[0].equals("item_view"));
// finally get the byte array from the tree, make a
// binary iterator and check its annotation handling
byte[] buf = dg.getBytes();
it = system().newReader(buf);
t = it.next();
assertSame("should be a struct", t, IonType.STRUCT);
ann = it.getTypeAnnotations();
assertTrue(ann.length == 1 && ann[0].equals("item_view"));
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class OffsetSpanBinaryReaderTest method testCurrentSpanBeyondMaxInt.
@Test
public void testCurrentSpanBeyondMaxInt() {
if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
// See ion-java/issues/382 and ion-java/issues/383.
return;
}
IonDatagram dg = system().newDatagram();
dg.add().newBlob(new byte[2000]);
byte[] binary = dg.getBytes();
readBeyondMaxInt(binary, IonType.BLOB);
}
use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class DataBindWriteTest method testSimpleObjectWriteBinary.
@Test
public void testSimpleObjectWriteBinary() throws Exception {
byte[] data = _writeAsBytes(new MyBean());
IonDatagram loadedDatagram = ion.newLoader().load(data);
assertEquals(expectedMyBean, loadedDatagram);
}
Aggregations