Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type parameters are checked for equality while isAssignableFrom expected #2155

Closed
frankfiedler opened this issue Oct 11, 2018 · 5 comments
Closed
Milestone

Comments

@frankfiedler
Copy link

I have a problem with the serialization of a class of mine with an acutal version of the jackson serialization. The last version working with my code is the 2.8.10 as far as I know.
The problem I see is that the serialization checks in file jackson-databind-2.9.5-sources.jar!/com/fasterxml/jackson/databind/type/TypeFactory.java:474 while I would expect the check to make sure that the field-type is only assignable-from the concrete instance of a field.

I prepared a testcase which I attach to this report.

testcase-plugin-serialization.zip

The entry point for my testcase is the class called MyTest. There you find a function

  • problem() : producing the problem
  • workaround() : working around the problem by doing the serialization in the problematic class manually

In the example the ProblematicPlugin has a value type named ValueAndState which implements Serializable. As the serializer checks for Serializable == ValueAndState the check fails while I think the check should do field.isAssignableFrom(valueAndStateInstance).

The class WorkaroundPlugin contains my current work around, doing the serialization of the members myself and just bypassing the check in the class itself.

I would like to ask for a change in the serializer checking for isAssignableFrom(..).

Any feedback and questions welcome.

@cowtowncoder
Copy link
Member

I am not 100% sure I fully understand your problem here, but keep in mind that TypeFactory is not responsible for enforcing assignment validity -- all it needs to do is to ensure that type resolution of generic types works as expected, and then resolved JavaType is used by other functionality such as JsonSerializers to determine validity. Exception may be triggered by TypeFactory, still, for some cases where serializers or deserializers try to combine static type declaration information with runtime type information -- this is sanity checking that is needed to avoid incorrect usage by custom code (to catch bugs in case caller passes incompatible arguments).

Having said that, there have been some issues, however, in which some cases of types that should not cause problems for serialization (but would for deserialization) being problematic. So it is possible you are hitting one such case. A few have been fixed for 2.9.x, caused by stricter type assignment verification during resolution, compared to 2.8.x.

I hope to look into the test case in near future, but right now I am quite overworked so that may take a while.

@frankfiedler
Copy link
Author

frankfiedler commented Oct 16, 2018 via email

@cowtowncoder cowtowncoder added this to the 2.9.8 milestone Nov 20, 2018
@cowtowncoder
Copy link
Member

@frankfiedler I finally had time to look again into this, and I see what you mean. I will relax the check a bit to allow assignment compatibility for interfaces as type parameters (and this may not be the last change but works here).

Thank you for submitting the issue; will be fixed in 2.9.8.

@frankfiedler
Copy link
Author

frankfiedler commented Nov 22, 2018 via email

@cowtowncoder
Copy link
Member

@frankfiedler Thank you for persisting on this and helping me improve handling!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants