FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
314 stars 136 forks source link

Unable to deserialize java.time.LocalDate with SMILE #203

Closed abelsromero closed 4 years ago

abelsromero commented 4 years ago

v 2.10.13

We are testing the use of SMILE with a current project and it seems that Java8 types like LocalDate are not treated. To manage them in JSON we add the provided modules without problems.

        return new ObjectMapper()
                .registerModule(new Jdk8Module())
                .registerModule(new JavaTimeModule());

But when adding the SmileFactory the error show below appears.

        return new ObjectMapper(new SmileFactory())
                .registerModule(new Jdk8Module())
                .registerModule(new JavaTimeModule());
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.LocalDate` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

Testing further we have also seen that other custom jackson serializers and deserializers and not invoked when using SMILE.

Is SMILE compatible with those types?

cowtowncoder commented 4 years ago

Use of Smile should not preclude use of Java 8 data types so yes, this usage should be supported.

Is there any possibility that whatever is serializing values did NOT use JavaTimeModule? Without registering module, serialization still "succeeds", but uses POJO introspection resulting in Object, instead of number or String.

abelsromero commented 4 years ago

Is there any possibility that whatever is serializing values did NOT use JavaTimeModule?

Apparently it was, the ObjectMapper was initialized in a way that the modules where not added. That also explains why other custom serializers did not work. Not it's working correctly, with also Optionals.

Many, many thanks! :smile:

cowtowncoder commented 4 years ago

@abelsromero Ah. That happens :)

Glad to hear things are working: Smile format has logical model very close to JSON so it really should work very similarly regarding datatypes.