Kevin created JOHNZON-223:
-----------------------------
Summary: Deserialization of objects with generic types leads to an
error
Key: JOHNZON-223
URL: https://issues.apache.org/jira/browse/JOHNZON-223
Project: Johnzon
Issue Type: Bug
Components: JSON-B
Affects Versions: 1.1.12
Reporter: Kevin
In our project we use generic containers e.g. for enums to enrich them with
additional information. For the serialization in Json we use an own adapter.
Serialization in Json works without problems, but deserialization into an
object results in an error:
{code:java}
javax.json.bind.JsonbException: Cannot cast
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl to
java.lang.Class{code}
>From my point of view the problem lies in the method
{code:java}
org.apache.johnzon.mapper.Mappings.findConverter line 570
final ParameterizedType type =
ParameterizedType.class.cast(decoratedType.getType());
final Type rawType = type.getRawType();
if (Class.class.isInstance(rawType)
&& Collection.class.isAssignableFrom(Class.class.cast(rawType))
&& type.getActualTypeArguments().length >= 1) {
typeToTest = type.getActualTypeArguments()[0];
} // TODO: map{code}
The condition checks here whether it is a collection, otherwise nothing else is
done for ParameterizedTypes.
However, the variable typeToTest should be set to rawType for
ParameterizedTypes so that a converter can be found afterwards. Otherwise
typeToTest remains a ParameterizedType and the query in line 576 if (converter
== null && Class.class.isInstance(typeToTest)) fails and no converter will be
searched.
A small test can be found here:
[https://gist.github.com/kevinwilken/12da681534053b776247697c6f24c296]
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)