0

I don't know if it is a Spring problems or jackson but see it please :

{
  "usersClients": [
    {
      "pkUsersClients": {
        "id": 2,
        "user": {
          "idUser": 31,
          "login": "EditUser",
          "pwd": "$2a$10$7G/GWrd5...",
          "locked": "F",
          "avatar": null
        },
        "client": {
          "idClient": 1,
          "name": "SOCIETY 1",
          "description": "TEST 1",
          "logo": "/9j/4QDCRXh..."
        }
      },
      "date_begin": null,
      "date_end": null,
      "enable": false,
      "user": 31,
      "idClient": 1
    },
    {
      "pkUsersClients": {
        "id": 3,
        "user": 31,
        "client": 1
      },
      "date_begin": 1464818400000,
      "date_end": null,
      "enable": false,
      "user": 31,
      "idClient": 1
    },
    {
      "pkUsersClients": {
        "id": 4,
        "user": 31,
        "client": {
          "idClient": 5,
          "name": "SOCIETY 99",
          "description": "TEST99",
          "logo": "iVBORw0KGgoAAAANSUh..."
        }
      },
      "date_begin": 1464818400000,
      "date_end": 1467237600000,
      "enable": false,
      "user": 31,
      "idClient": 5
    }
  ]
}

As you can see, first pkUsersClients has user and client with information like login or name. The last pkUsersClients too. But the second, as it has the same id and user of the first pkUsersClients, informations are not developped :/

Do you have an idea why ? thanks

Paladice
  • 247
  • 4
  • 19
  • Can you show the class definitions? Do you have any attributes, for example `@JsonIdentityInfo` anywhere? – tasseKATT Jun 02 '16 at 16:04
  • Hello. Yes, I have @JsonIdentityInfo. My classes are specify here : http://stackoverflow.com/questions/37591485/spring-jpa-embeddable-class-send-int-instead-of-object However, I commented JsonIdentityInfo and List in User and Client, and now it works. But I don't know if it is a good thing ;) – Paladice Jun 03 '16 at 07:22

1 Answers1

1

I'm not a Java developer but it looks like you are using @JsonIdentityInfo or something similar to only serialize the first occurrence of a child object and then use the id instead.

My guess is that this is used to either limit the amount of data sent and/or to handle the case of cyclic object graphs (when a child object has a reference back to the parent).

Try removing the @JsonIdentityInfo and see if you get the expected output without it.

If you have cyclic object references you might be required to keep @JsonIdentityInfo and handle the id - object mapping manually on the client.

tasseKATT
  • 38,470
  • 8
  • 84
  • 65