use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class DataBindWriteTest method testIntArrayWriteBinary.
@Test
public void testIntArrayWriteBinary() throws Exception {
byte[] data = _writeAsBytes(new int[] { 1, 2, 3 });
assertNotNull(data);
IonDatagram loadedDatagram = ion.newLoader().load(data);
assertEquals(expectedArray, loadedDatagram);
}
use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class DataBindWriteTest method testIntArrayWriteText.
@Test
public void testIntArrayWriteText() throws Exception {
IonObjectMapper m = new IonObjectMapper(IonFactory.forTextualWriters());
IonDatagram loadedDatagram = ion.newLoader().load(m.writeValueAsString(new int[] { 1, 2, 3 }));
assertEquals(expectedArray, loadedDatagram);
}
use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class DataBindWriteTest method testSimpleObjectWriteText.
/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/
@Test
public void testSimpleObjectWriteText() throws Exception {
IonObjectMapper m = IonObjectMapper.builderForTextualWriters().build();
// now parse it using IonLoader and compare
IonDatagram loadedDatagram = ion.newLoader().load(m.writeValueAsString(new MyBean()));
assertEquals(expectedMyBean, loadedDatagram);
}
use of com.amazon.ion.IonDatagram 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.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class IonObjectMapper method writeValueAsIonValue.
/**
* Method that can be used to map any Java value to an IonValue.
*/
public IonValue writeValueAsIonValue(Object value) throws IOException {
// 04-Jan-2017, tatu: Bit of incompatiblity wrt 2.x handling: should this result in
// Java `null`, or Ion null marker? For now, choose latter
/*
if (value == null) {
return null;
}
*/
IonFactory f = tokenStreamFactory();
IonDatagram container = f._system.newDatagram();
try (IonWriter writer = f._system.newWriter(container)) {
writeValue(writer, value);
IonValue result = container.get(0);
result.removeFromContainer();
return result;
}
}
Aggregations