Search in sources :

Example 86 with IonValue

use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.

the class EnumAsIonSymbolSerializationTest method testUsingToString.

@Test
public void testUsingToString() throws Exception {
    final IonValue EXP = ION_SYSTEM.singleValue("some_value");
    Assert.assertEquals(EXP, newMapper(false, true).writeValueAsIonValue(SomeEnum.SOME_VALUE));
    Assert.assertEquals(EXP, newMapper(true, true).writeValueAsIonValue(SomeEnum.SOME_VALUE));
}
Also used : IonValue(com.amazon.ion.IonValue) Test(org.junit.Test)

Example 87 with IonValue

use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.

the class IonParserTest method testFloatType.

@Test
public void testFloatType() throws IOException {
    final ObjectReadContext ctxt = ObjectReadContext.empty();
    final byte[] data = "{ score:0.291e0 }".getBytes();
    IonSystem ion = IonSystemBuilder.standard().build();
    final IonValue ionFloat = ion.newFloat(Float.MAX_VALUE);
    IonReader reader = ionFloat.getSystem().newReader(data, 0, data.length);
    // Find the object
    reader.next();
    // Step into the object
    reader.stepIn();
    // Step next.
    reader.next();
    final IonParser floatParser = ionFactory.createParser(ctxt, reader);
    Assert.assertEquals(JsonParser.NumberType.DOUBLE, floatParser.getNumberType());
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonReader(com.amazon.ion.IonReader) ObjectReadContext(com.fasterxml.jackson.core.ObjectReadContext) Test(org.junit.Test)

Example 88 with IonValue

use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.

the class IonParserTest method testParserCapabilities.

@Test
public void testParserCapabilities() throws Exception {
    IonSystem ion = IonSystemBuilder.standard().build();
    Integer intValue = Integer.MAX_VALUE;
    IonValue ionInt = ion.newInt(intValue);
    try (IonParser p = new IonFactory().createParser(ObjectReadContext.empty(), ionInt)) {
        // 15-Jan-2021, tatu: 2.14 added this setting, not enabled in
        // default set
        Assert.assertTrue(p.streamReadCapabilities().isEnabled(StreamReadCapability.EXACT_FLOATS));
    }
}
Also used : BigInteger(java.math.BigInteger) IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) Test(org.junit.Test)

Example 89 with IonValue

use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.

the class PolymorphicRoundtripTest method testWithDateAsTimestamp.

@Test
public void testWithDateAsTimestamp() throws IOException {
    resolveAllTypes = true;
    ObjectMapper ionDateMapper = IonObjectMapper.builder().addModule(new IonAnnotationModule()).enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
    long etime = 1449191916000L;
    java.util.Date uDate = new java.util.Date(etime);
    java.sql.Date sDate = new java.sql.Date(etime);
    // java.util.Date can serialize properly
    String serialized = ionDateMapper.writeValueAsString(uDate);
    IonValue ionVal = ionSystem.singleValue(serialized);
    Assert.assertEquals("Expected date to be serialized into an int", IonType.INT, ionVal.getType());
    // java.sql.Date can serialize properly
    serialized = ionDateMapper.writeValueAsString(sDate);
    ionVal = ionSystem.singleValue(serialized);
    Assert.assertEquals("Expected date to be serialized into an int", IonType.INT, ionVal.getType());
}
Also used : IonValue(com.amazon.ion.IonValue) IonObjectMapper(com.fasterxml.jackson.dataformat.ion.IonObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 90 with IonValue

use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.

the class IonValueDeserializerTest method shouldBeAbleToDeserializeAnnotatedNullStruct.

@Test
public void shouldBeAbleToDeserializeAnnotatedNullStruct() throws Exception {
    IonValue ion = ion("foo::null.struct");
    IonValue data = ION_VALUE_MAPPER.readValue(ion, IonValue.class);
    assertEquals(ion, data);
    assertEquals(1, data.getTypeAnnotations().length);
    assertEquals("foo", data.getTypeAnnotations()[0]);
}
Also used : IonValue(com.amazon.ion.IonValue) 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