On Thu, Feb 22, 2018 at 6:01 AM, Ayush Gupta <ayushg...@gmail.com> wrote:

>
> 0down votefavorite
> <https://stackoverflow.com/questions/48929215/jackson-upgrade-compatibility-issues-from-2-6-1-to-2-8-7#>
>
> I have upgraded jackson from version 2.6.1 to 2.8.7 in my project
> recently. And I'm facing the following issue:
>
> When I try to deserialize the data I get back using an object mapper, if I
> don't provide type arguments for constructing from canonical in version
> 2.6.1, it works fine. So for example, the following code runs fine on 2.6.1:
>
> returnType = "java.util.List";
> objectMapper.getTypeFactory().constructFromCanonical(returnType);
>
> But on 2.8.7, it gives an exception. The stacktrace of the exception:
>
> java.rmi.RemoteException: java.lang.NullPointerException:null.
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory._fromVariable(TypeFactory.java:1421)
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1182)
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory._fromParamType(TypeFactory.java:1404)
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1172)
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory._resolveSuperInterfaces(TypeFactory.java:1318)
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1261)
>     at 
> com.fasterxml.jackson.databind.type.TypeParser.parseType(TypeParser.java:60)
>     at 
> com.fasterxml.jackson.databind.type.TypeParser.parse(TypeParser.java:33)
>     at 
> com.fasterxml.jackson.databind.type.TypeFactory.constructFromCanonical(TypeFactory.java:544)
>     at 
> foo.company.package.serialize.Serializer.deserialize(Serializer.java:355)
>
> But if I pass the string with the complete type information, even if only
> pass it as Object, ie, returnType = "java.util.List<java.lang.Object>";,
> it works fine.
>
> Is there a way to make this backward compatible?
>
>
>

Ok. This method really isn't intended for usage outside of framework (it
was added to support polymorphic (de)serialization),
but it seems reasonable to allow non-generic types too. Contract should be
that anything `JavaType.toCanonical()`
produces should be acceptable as input for
`TypeFactory.constructFromCanoncial()`.

However.... in your case, input string really is NOT canonical: it is
missing type parameter definitions.
So it is invalid input, even if earlier versions accepted it.

Could you file an issue for `jackson-databind`? I can have a look and
consider what to do here; code could either
give better exception message (indicating nature of the problem), or,
possibly, produce equivalent of `List<?>`.

As a workaround I would suggest checking if there is generic type info (any
`<` in there?); if not,
just use `Class.forName()`, then construct type with that. If there is, use
constructFromCanonical.
Fix would go in 2.9.5 although I might backport it in 2.8 -- but there will
only be micro-patches for
2.8 and it is unclear if and when databind one would be relased.

-+ Tatu +-




> I have also posted a StackOverflow question here: https://stackoverflow.
> com/questions/48929215/jackson-upgrade-compatibility-
> issues-from-2-6-1-to-2-8-7
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to