Skip to content

ION deserialization type change from Double to Float in 2.17.0 #490

@fhussonnois

Description

@fhussonnois

Hello, on my current projet we have tried to upgrade our dependencies from Jackson 2.16.2 to 2.17.0. But we're noticing a difference in the way the data is deserialized with ION.

Previsouly, the deserialization of either a float (e.g., 42F) or a double (e.g., 42D) was giving a double for both. This behavior changed and we now get float for both.

Here is a simple test for reproducing:

    @Test
    void test() throws IOException {
        // Configure IonSystem
        final var catalog = new SimpleCatalog();
        final var textWriterBuilder = IonTextWriterBuilder.standard()
            .withCatalog(catalog)
            .withCharsetAscii()
            .withWriteTopLevelValuesOnNewLines(true); // write line separators on new lines instead of spaces
        final var binaryWriterBuilder = IonBinaryWriterBuilder.standard()
            .withCatalog(catalog)
            .withInitialSymbolTable(_Private_Utils.systemSymtab(1));
        final var readerBuilder = IonReaderBuilder.standard()
            .withCatalog(catalog);
        
        IonSystem ionSystem = newLiteSystem(textWriterBuilder, (_Private_IonBinaryWriterBuilder) binaryWriterBuilder, readerBuilder);
        
        // Create ObjectMapper
        final ObjectMapper om = new IonObjectMapper(new IonFactory(ionSystem))
            .setSerializationInclusion(JsonInclude.Include.ALWAYS)
            .registerModule(new IonModule());
        
        // Jackson: 2.16.2 {double:42e0,float:42e0,long:9223372036854775807,int:2147483647}
        // Jackson: 2.17.0 {double:42e0,float:42e0,long:9223372036854775807,int:2147483647}
        byte[] serialized = om.writeValueAsBytes(Map.of(
            "float", 42F,
            "double", 42D,
            "int", Integer.MAX_VALUE,
            "long", Long.MAX_VALUE)
        );
        
        Map deserialized = om.readValue(serialized, Map.class);
        Assertions.assertEquals(42D, deserialized.get("float")); // FAILED with Jackson 2.17.0
        Assertions.assertEquals(42D, deserialized.get("double"));  // FAILED with Jackson 2.17.0
        Assertions.assertEquals(Integer.MAX_VALUE, deserialized.get("int"));
        Assertions.assertEquals(Long.MAX_VALUE, deserialized.get("long"));
    }

Deserialization results:

Jackson 2.16.2
jackson-2 16 2-ion

Jackson 2.17.0
jackson-2 17 0-ion

Do you know where this change might come from?

Thank you for your help.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions