use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.
the class SerializationAnnotationsTest method testNativeTypeIdsEnabledOnWriteByDefault.
@Test
public void testNativeTypeIdsEnabledOnWriteByDefault() throws IOException {
IonObjectMapper mapper = new IonObjectMapper();
IonValue subclassAsIon = mapper.writeValueAsIonValue(subclass);
assertEqualIonValues(SUBCLASS_TYPED_BY_ANNOTATION, subclassAsIon);
BaseClass roundTripInstance = mapper.readValue(subclassAsIon, BaseClass.class);
assertCorrectlyTypedAndFormed(subclass, roundTripInstance);
}
use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.
the class SerializationAnnotationsTest method testNativeTypeIdsDisabledStillReadsNativeTypesSuccessfully.
@Test
public void testNativeTypeIdsDisabledStillReadsNativeTypesSuccessfully() throws IOException {
// native type ids enabled by default
IonObjectMapper writer = new IonObjectMapper();
IonValue subclassAsIon = writer.writeValueAsIonValue(subclass);
assertEqualIonValues(SUBCLASS_TYPED_BY_ANNOTATION, subclassAsIon);
IonObjectMapper reader = IonObjectMapper.builderForTextualWriters().disable(IonGenerator.Feature.USE_NATIVE_TYPE_ID).build();
BaseClass roundTripInstance = reader.readValue(subclassAsIon, BaseClass.class);
assertCorrectlyTypedAndFormed(subclass, roundTripInstance);
}
use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.
the class IonValueMapperTest method assertRoundTrip.
private void assertRoundTrip(String ion, Class<?> clazz) throws IOException {
IonValue expected = ionSystem.singleValue(ion);
Object o = ionValueMapper.readValue(expected, clazz);
IonValue actual = ionValueMapper.writeValueAsIonValue(o);
assertEquals(expected, actual);
}
use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.
the class IonParserTest method testGetNumberTypeAndValue.
@Test
public void testGetNumberTypeAndValue() throws Exception {
IonSystem ion = IonSystemBuilder.standard().build();
Integer intValue = Integer.MAX_VALUE;
IonValue ionInt = ion.newInt(intValue);
IonParser intParser = ionFactory.createParser(EMPTY_READ_CTXT, ionInt);
Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, intParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.INT, intParser.getNumberType());
Assert.assertEquals(intValue, intParser.getNumberValue());
Long longValue = Long.MAX_VALUE;
IonValue ionLong = ion.newInt(longValue);
IonParser longParser = ionFactory.createParser(EMPTY_READ_CTXT, ionLong);
Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, longParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.LONG, longParser.getNumberType());
Assert.assertEquals(longValue, longParser.getNumberValue());
BigInteger bigIntValue = new BigInteger(Long.MAX_VALUE + "1");
IonValue ionBigInt = ion.newInt(bigIntValue);
IonParser bigIntParser = ionFactory.createParser(EMPTY_READ_CTXT, ionBigInt);
Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, bigIntParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.BIG_INTEGER, bigIntParser.getNumberType());
Assert.assertEquals(bigIntValue, bigIntParser.getNumberValue());
Double decimalValue = Double.MAX_VALUE;
IonValue ionDecimal = ion.newDecimal(decimalValue);
IonParser decimalParser = ionFactory.createParser(EMPTY_READ_CTXT, ionDecimal);
Assert.assertEquals(JsonToken.VALUE_NUMBER_FLOAT, decimalParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.BIG_DECIMAL, decimalParser.getNumberType());
Assert.assertTrue(new BigDecimal("" + decimalValue).compareTo((BigDecimal) decimalParser.getNumberValue()) == 0);
Double floatValue = Double.MAX_VALUE;
IonValue ionFloat = ion.newFloat(floatValue);
IonParser floatParser = ionFactory.createParser(EMPTY_READ_CTXT, ionFloat);
Assert.assertEquals(JsonToken.VALUE_NUMBER_FLOAT, floatParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.DOUBLE, floatParser.getNumberType());
Assert.assertEquals(floatValue, floatParser.getNumberValue());
BigDecimal bigDecimalValue = new BigDecimal(Double.MAX_VALUE + "1");
IonValue ionBigDecimal = ion.newDecimal(bigDecimalValue);
IonParser bigDecimalParser = ionFactory.createParser(EMPTY_READ_CTXT, ionBigDecimal);
Assert.assertEquals(JsonToken.VALUE_NUMBER_FLOAT, bigDecimalParser.nextToken());
Assert.assertEquals(JsonParser.NumberType.BIG_DECIMAL, bigDecimalParser.getNumberType());
Assert.assertTrue(bigDecimalValue.compareTo((BigDecimal) bigDecimalParser.getNumberValue()) == 0);
}
use of com.amazon.ion.IonValue 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);
}
Aggregations