4

I am using Jackson's Hibernate4Module to deal with the serialization issues when dealing with a lazily loaded proxy in a Spring Data Rest project.

In general it solves the issue of Jackson trying to serialise uninitialized proxies however one side effect is that the JSON output differs:

Fetched directly: api/cases/5400

{
   "id": 5400,
   "practiceReference": "DWPYI9"
}

Fetched via a lazily loaded @ManyToOne: api/submissions/11901/parentCase

{
   "content": {
      "id": 5400,
      "practiceReference": "DWPYI9"
   }
}

Fetched via a non-lazily loaded @ManyToOne: api/submissions/11901/parentCase

{
   "id": 5400,
   "practiceReference": "DWPYI9"
}

As can be seen in the above, the JSON representation differs when serializing a lazy @ManyToOne association: the entity is wrapped in the "content" node.

If the association is non-Lazy then the same representation is written regardless of the path.

Is there a reason for this and can the additional "content" node somehow be prevented?

Update

I have found the same (deleted) question here:

https://stackoverflow.com/questions/33194554/two-different-resulting-jsons-when-serializing-lazy-objects-and-simple-objects

which is referenced from:

https://github.com/FasterXML/jackson-datatype-hibernate/issues/77

Also reported here so seems like a known issue:

https://github.com/FasterXML/jackson-datatype-hibernate/issues/97

Community
  • 1
  • 1
Alan Hay
  • 22,665
  • 4
  • 56
  • 110

0 Answers0