Search in sources :

Example 96 with IonValue

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);
}
Also used : IonValue(com.amazon.ion.IonValue) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 97 with IonValue

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);
}
Also used : IonValue(com.amazon.ion.IonValue) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) Test(org.junit.Test)

Example 98 with IonValue

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

Example 99 with IonValue

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);
}
Also used : BigInteger(java.math.BigInteger) IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 100 with IonValue

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);
}
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)

Aggregations

IonValue (com.amazon.ion.IonValue)185 Test (org.junit.Test)115 IonSequence (com.amazon.ion.IonSequence)61 SymbolTable (com.amazon.ion.SymbolTable)21 IonDatagram (com.amazon.ion.IonDatagram)20 IonStruct (com.amazon.ion.IonStruct)18 IonInt (com.amazon.ion.IonInt)16 IOException (java.io.IOException)14 IonReader (com.amazon.ion.IonReader)13 IonSystem (com.amazon.ion.IonSystem)12 Result (software.amazon.qldb.Result)11 SymbolToken (com.amazon.ion.SymbolToken)10 ArrayList (java.util.ArrayList)10 IonString (com.amazon.ion.IonString)9 IonException (com.amazon.ion.IonException)7 IonType (com.amazon.ion.IonType)6 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)6 Event (com.amazon.tools.events.Event)5 com.amazon.ion.impl._Private_IonValue (com.amazon.ion.impl._Private_IonValue)4 EventType (com.amazon.tools.events.EventType)4