Deserialization with PTH and JsonIdentityInfo in untyped collections

22 views
Skip to first unread message

Alex T

unread,
May 14, 2020, 12:00:47 PM5/14/20
to jackson-user
Hi Tatu!

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.

How to serialize untyped collections properly?

Alex T

unread,
Jul 1, 2020, 6:08:49 PM7/1/20
to jackson-user
Anybody here? :)

Tatu Saloranta

unread,
Jul 1, 2020, 6:33:19 PM7/1/20
to jackson-user
Probably worth filing an issue for. I don't know what might be wrong
from JSON alone, type declarations are necessary (and included in the
test repo).

-+ Tatu +-
> --
> You received this message because you are subscribed to the Google Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/aee933cb-80ca-4798-bde3-31386231f400o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages