Deprecated findSerializationType might be breaking refineSerializationType (v2.8.1)

78 views
Skip to first unread message

JonyD

unread,
Aug 11, 2016, 11:33:57 AM8/11/16
to jackson-user
In https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java
the method findSerializationType is deprecated since v2.7 and returns always null.
The method refineSerializationType (which is the new method that should be used instead of findSerializationType) uses/calls the findSerializationType in some parts with logic [if(... ].
I think this makes refineSerializationType broken.

I get the following exception in a custom Serialization:
com.fasterxml.jackson.databind.JsonMappingException: Can not refine serialization key type [simple type, class java.util.Currency] into java.lang.String; types not related
        at com
.fasterxml.jackson.databind.AnnotationIntrospector.refineSerializationType(AnnotationIntrospector.java:891)
        at com
.fasterxml.jackson.databind.ser.PropertyBuilder.findSerializationType(PropertyBuilder.java:188)
        at com
.fasterxml.jackson.databind.ser.PropertyBuilder.buildWriter(PropertyBuilder.java:75)
        at com
.fasterxml.jackson.databind.ser.BeanSerializerFactory._constructWriter(BeanSerializerFactory.java:818)
        at com
.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanProperties(BeanSerializerFactory.java:609)
        at com
.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:390)
        at com
.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:273)
        at com
.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
        at com
.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:159)
        at com
.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1272)
        at com
.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1222)
        at com
.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:499)
        at com
.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:697)
        at com
.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:270)
        at com
.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672)
        at com
.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3030)





Tatu Saloranta

unread,
Aug 11, 2016, 2:11:40 PM8/11/16
to jackso...@googlegroups.com
Your suggestion sounds plausible, but to fix it, as well as to guard against regression, it would be necessary to have a way to reproduce the problem.
So if there is any way you could suggest a way to trigger the problem that would be great.

Exception, however, would seem to indicate some other kind of problem... either way it would be good to figure out what is going wrong.

-+ Tatu +-



--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscribe@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JonyD

unread,
Aug 12, 2016, 8:11:51 AM8/12/16
to jackson-user
I've created a repo in https://github.com/JonyD/my-app with a failing test.
The pom.xml is a bit messy but it's important because of dependencies.

just do "mvn clean install" to run the failing test.
I hope this helps and hope you can find the bug.

Notice that with jackson version 2.4.6 the test passes, but with version 2.8.1 it does not.
To verify this, just change in pom.xml the string:
<jackson.version>2.8.1</jackson.version>

with the following
<jackson.version>2.4.6</jackson.version>


Regards,
J

Tatu Saloranta

unread,
Aug 16, 2016, 6:59:41 PM8/16/16
to jackso...@googlegroups.com
-+ Tatu +-



--

Tatu Saloranta

unread,
Sep 9, 2016, 12:07:55 AM9/9/16
to jackso...@googlegroups.com
As a follow up, turns out that the problem is, as far as I can see:


in the code itself. Issue has full detail, but basically Jackson is indicating a real problem in annotation for

@JsonSerialize(.... keyAs=String.class)
public Map<Currency, ...> getRevenue() { .... }

because that would require cast from `Currency` into `String`, before serialization, and that is not valid in Java. I suspect 2.4.6 simply ignored this annotation, or managed to work despite it (getting default key serializer that uses `toString()` for result).
Anyway, this is what triggers the exception.

I'll see if there is a way to improve exception message itself, however; it is bit difficult to backtrack from it as things are.

-+ Tatu +-




On Fri, Aug 12, 2016 at 5:11 AM, JonyD <joaon...@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages