question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deserialization with Default Typing (PTH) and `@JsonIdentityInfo` in untyped collections

See original GitHub issue

I need to serialize/deserialize untyped collections, and I get issue when deserialing. I push failing unit test in my repository: https://github.com/alex-t0/deserialization-fail-example/blob/master/src/test/java/deserialization/fail/example/DeserializationFromUntypedCollectionsTest.java.

In this test I have simple User class and dummy UserContainer class, that has one User property. Next, I create an array of 2 elements: user and userContainer with reference to same user.

When first element of array is user, and second is container - deserialization works fine. I get this serialized string:

[
    "java.util.ArrayList",
    [
        [
            "deserialization.fail.example.User",
            {
                "id": 42,
                "login": "cool_man"
            }
        ],
        [
            "deserialization.fail.example.UserContainer",
            {
                "user": 42
            }
        ]
    ]
]

Because jackson knows what is 42 here.

But if I put userContainer at first place in my array, and user at second place, serialized data would be

[
    "java.util.ArrayList",
    [
        [
            "deserialization.fail.example.UserContainer",
            {
                "user": [
                    "deserialization.fail.example.User",
                    {
                        "id": 42,
                        "login": "cool_man"
                    }
                ]
            }
        ],
        42
    ]
]

So, user serialized as id, but no type information saved about user. And when I deserialize this I get an array with Integer 42 at second place, not user.

I think that when serializing untyped collection jackson must “start from scratch” for every element, and “forget” previously found object id’s. Size of json will increase, but will work.

Maу be somebody offer better solution.

Thanks!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Jul 2, 2020

Ok thanks. I hope to have to look into this in near future: removal of hibernate from test should help pinpoint issue itself.

0reactions
alex-t0commented, Jul 2, 2020

@cowtowncoder, may be you remove hibernate label from this issue? And thank you for help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure Jackson to deserialize named types with ...
The produced JSON certainly has all the information Jackson needs to determine the type correctly. You've provided Jackson with the following
Read more >
SUSE-SU-2022:1678-1: important: Security update for jackson ...
Type ' should accept array of names + Jackson version alignment with ... does not support deserializing new Java 9 unmodifiable collections + ......
Read more >
Jackson 2.10: Safe Default Typing - cowtowncoder - Medium
Safe Default Typing means that in addition to specifying the main existing criteria for default typing — which classes should automatically use ...
Read more >
Index (jackson-databind 2.10.4 API) - javadoc.io
Helper class to contain default mappings for abstract JDK Collection and Map types. ... cheks when coercing integral values for untyped deserialization.
Read more >
SUSE alert SUSE-SU-2022:1678-1 (jackson-databind ...
Type ' should accept array of names + Jackson version alignment with ... does not support deserializing new Java 9 unmodifiable collections + ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found