Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

java - Issue Serializing Lazy @ManyToOne

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...