1

My objective is to avoid the creation of the same object twice. I want to deserialize an array of two objects that contain the same child object, this is the JSON object that I want to deserialize

  [
     {
        @id: 98,
        relatedPackage: {@id:99, receivedOn:1374012807237, packingTypeFk:1,…}
     },
     {
        @id: 101,
        relatedPackage: {@id:99, receivedOn:1374012807237, packingTypeFk:1,…}
     }
  ]

and this is the POJO

@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
public class Package extends StampedModel {
...
}

In the last code you can see that I put the annotation @JsonIdentityInfo to achieve my objective but it doesn't do the job. Always that I send this array to the server, it creates two diferent packages.

What am I doing Wrongo?

Luis Vargas
  • 2,466
  • 2
  • 15
  • 32

2 Answers2

1

To solve the problem I need to send the first related package only one time, and the next times send only the ID number. ie.

[
   {
      @id: 98,
      relatedPackage: {@id:99, receivedOn:1374012807237, packingTypeFk:1,…}
   },
 {
      @id: 101,
      relatedPackage: 99
   }
]
Luis Vargas
  • 2,466
  • 2
  • 15
  • 32
0

As far as I know, the "identity" information does not enforce instance identity. It only ensures that two object conforming to that identity are regarded as equal.

You can implement custom deserializers with Jackson. Then you would also implement class instance control (either through an instance manager, or within the value classes themselves). HTH

Community
  • 1
  • 1
LexLythius
  • 1,904
  • 1
  • 12
  • 20