com.fasterxml.jackson.databind.JsonMappingException: Already had POJO for id (java.util.UUID)

251 views
Skip to first unread message

Syed Iftekharuddin

unread,
Nov 17, 2022, 12:32:55 PM11/17/22
to jackson-user
Hi,
I have problem with Deserialization of entities with association.
The entities are as follows:

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Process.class)
public class Process implements Serializable  {

    // some properties here
    private UUID id;
   
    private List<User> users = new ArrayList<>();

    private List<ProcessHistory> processHistorySet = new ArrayList<>();

    private List<AnsweredQuestionnaire> answeredQuestionnaires = new ArrayList<>();
}

public class ProcessHistory implements Serializable {
    private UUID id;

    @JsonIgnore
    private Process process;

    private User user;
}


@JsonIdentityInfo(generator= ObjectIdGenerators.UUIDGenerator.class, property = "id", scope = AnsweredQuestionnaire.class)
public class AnsweredQuestionnaire implements Serializable {

    private UUID id;

    private Process process;
}


@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = User.class)
public class User implements Serializable {

    private UUID id;

    private List<Process> processes = new ArrayList<>();
}

Using the entities with association will cause some problem during dserialization and cause the following error :

com.fasterxml.jackson.databind.JsonMappingException: Already had POJO for id (java.util.UUID)
[[ObjectId: key=4c3cb331-bbbc-4105-bc3e-ddca3fea485d, type=com.fasterxml.jackson.databind.deser.impl.PropertyBasedObjectIdGenerator, scope=com.app.User]]
(through reference chain: com.app.User["processes"]->java.util.ArrayList[0]->com.app.Process["users"]->java.util.ArrayList[0]->com.app.User["id"])
java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: Already had POJO for id (java.util.UUID)
[[ObjectId: key=4c3cb331-bbbc-4105-bc3e-ddca3fea485d, type=com.fasterxml.jackson.databind.deser.impl.PropertyBasedObjectIdGenerator, scope=com.app.User]]
(through reference chain: com.app.User["processes"]->java.util.ArrayList[0]->com.app.Process["users"]->java.util.ArrayList[0]->com.app.User["id"])

Your help is greatly appreciated.
Thank you.

Tatu Saloranta

unread,
Nov 17, 2022, 12:37:19 PM11/17/22
to jackso...@googlegroups.com
The most likely explanation would be that the same id was included for
multiple User instances in incoming JSON.

But other than that, a reproduction (ideally minimal unit test) would
be needed to figure out if there is a real problem
or if this is due to some configuration problem or such.

-+ Tatu +-

Syed Iftekharuddin

unread,
Nov 17, 2022, 12:48:23 PM11/17/22
to jackso...@googlegroups.com
Hi Tatu, 
Thank you very much for the response. 
I will take a note of your comment and prepare a testable version. 

Regards
Iftekhar

--
You received this message because you are subscribed to a topic in the Google Groups "jackson-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jackson-user/TfPCxDSD-Ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jackson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10gGPM%3Dg2obJ0aBEQzNOv%2BMSchDVHm2gNnEwBRshbxZZzg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages