When TypeFactory.constructFromCanonical(returnType) is used in 2.6.1, the returnType string for generic types is not expected to have parameterized type information. For example, the following code runs fine on 2.6.1:
returnType = "java.util.List";
objectMapper.getTypeFactory().constructFromCanonical(returnType);
But in version 2.8.7, the same code gives a NullPointerException with the stack trace:
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 the returnType string is passed with the generic type information, even if it is passed as Object, ie, returnType = "java.util.List<java.lang.Object>";, it works fine.
I have 2 questions, is there a way to make this change backward compatible? If not, how can I work around this? PS: The workaround given by Tatu in the mailing list is not clear to me, if someone can give me an example, it'd be great help. Thanks!
Link to google groups thread.
When
TypeFactory.constructFromCanonical(returnType)is used in2.6.1, thereturnTypestring for generic types is not expected to have parameterized type information. For example, the following code runs fine on 2.6.1:But in version
2.8.7, the same code gives aNullPointerExceptionwith the stack trace:But if the
returnTypestring is passed with the generic type information, even if it is passed asObject, ie,returnType = "java.util.List<java.lang.Object>";, it works fine.I have 2 questions, is there a way to make this change backward compatible? If not, how can I work around this? PS: The workaround given by Tatu in the mailing list is not clear to me, if someone can give me an example, it'd be great help. Thanks!
Link to google groups thread.