Skip to content

Invalid JavaType for "org.eclipse.persistence.indirection.IndirectList" class #3361

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

Closed
chkp-royl opened this issue Dec 27, 2021 · 6 comments
Closed
Labels
need-test-case To work on issue, a reproduction (ideally unit test) needed

Comments

@chkp-royl
Copy link

chkp-royl commented Dec 27, 2021

Describe the bug
I need to upgrade Jackson package from version 2.5.0 to 2.11.3.

When deserialize JSON field from type "org.eclipse.persistence.indirection.IndirectList", the function constructSpecializedType in TypeFactory class returns invalid JavaType than in my current version (2.5.0).

Version information
Which Jackson version(s) was this for?
2.11.3

Expected behavior
Return same JavaType object like in version 2.5.0.
The elements in IndirectList have custom deserializer and it's not being called at all. the logic in version 2.11.3 deserialize the elements as String object.

Additional context
See _elementType diff.
Should be simple type of CPUUID (which is my internal class) and not Object.

Version 2.5.0
image
Version 2.11.3
image

Thanks in advance,
Roy

@chkp-royl chkp-royl added the to-evaluate Issue that has been received but not yet evaluated label Dec 27, 2021
@cowtowncoder
Copy link
Member

cowtowncoder commented Dec 29, 2021

First things first: 2.11.3 is not the latest patch for 2.11 so the issue should have been tested against 2.11.4.
But more importantly 2.11.x branch is not maintained so reproduction really is needed for something more recent: ideally
2.13.1, or alternatively 2.12.6

Description itself does not quite explain the problem so what I'd really need is a reproduction like unit test.
Ideally without 3rd party types (instead copy-paste type definition in test), but if that is not possible, then including Maven dependency to test type.

But first it would be good to verify the issue exists in 2.13.1 or 2.12.6.

@cowtowncoder cowtowncoder added need-test-case To work on issue, a reproduction (ideally unit test) needed and removed to-evaluate Issue that has been received but not yet evaluated labels Dec 29, 2021
@chkp-royl
Copy link
Author

Thanks for your quick respond.
I tested both versions 2.13.1 and 2.12.6 and it doesn't work.

After some debugging I found out that issue happens from version 2.7.0.
On version 2.6.7 it works good and I suspect the bug relate to issue #76 (type handling system)

I am working on unit test with no 3rd party dependencies. This is challenging because we have internal logic when de serializing objects from JSON to Java so I hope to share it with you ASAP.

Regards,
Roy

@chkp-royl
Copy link
Author

chkp-royl commented Jan 12, 2022

After more investigation I think I found the root cause of this bug. It's probably relate to serializing and not to deserializing like I thought at the beginning.
See how my java object is serialized to JSON:

  1. Version 2.5.0:
    ["objects.A",{"myList":["java.util.ArrayList",["some string"]]}]

  2. Version 2.11.3:
    ["objects.A",{"myList":["java.util.ArrayList",[["objects.B","some string"]]]}]

For the given classes:

public class A
{
    private ArrayList<B> myList;
}

public class B
{
    private String text;
}

(class B serialized ONLY to text value)

The difference is the class path that added per object in "myList" member which not happen in version 2.5.0.
When I try to deserialize objects using newer jackson version (after 2.6.7) that were serialized in version 2.5.0 this bug happen.
Do you know if I should add logic that convert old serialize to new jackson version standards or something like that? How should I add this class path in version 2.5.0 so the serialization will be the same?

Regards,
Roy

@cowtowncoder
Copy link
Member

cowtowncoder commented Jan 17, 2022

There is no way to try to configure the way Type Ids are written, except by annotations. Versions 2.5 and 2.6 are very very old by now, so I don't think anything in Jackson will help you handle the difference unfortunately.

Changes in such cases should only have occurred if the older version (2.5.x) had a bug in serialization code, and that was fixed in later version (2.6.x). Otherwise structure should not have changed.

Given this, I am not sure I can give much more help: if it was possible to have a test case where a new (2.12.6 f.ex) version wrote something that cannot be read with that version, we'd have a bug to work on.
But unfortunately in this case it seems likely that a bug fix caused incompatibility. But with such an old version I don't really have time to dig any deeper.

@chkp-royl
Copy link
Author

chkp-royl commented Jan 17, 2022

Ok, thanks for your help!
What is the best practice in such case? Do I need to run same Jackson version when I do serialization & deserialization?
Currently I do serialization in old version (2.5.0) and deserialization in new version (2.11.3 for example).

Regards,
Roy

@cowtowncoder
Copy link
Member

No, there should not be a requirement for versions to match; different minor versions should match.

But unfortunately in your case there seems to have been a change where this did not work.

As a general guidance I do think it is good idea to try to keep similar versions of Jackson across all your systems, migrating over time. But that should not be required for data / structure compatibility.

Another thing to consider is that some level of integration testing would allow verification of compatibility of new Jackson versions with your existing use cases: if issues are uncovered early enough (f.ex when new Jackson Release Candidates are released) they can be addressed to avoid compatibility issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-test-case To work on issue, a reproduction (ideally unit test) needed
Projects
None yet
Development

No branches or pull requests

2 participants