Issue Serializing Lazy @ManyToOne

假装没事ソ 提交于 2019-12-29 06:29:08

问题


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

来源:https://stackoverflow.com/questions/42395831/issue-serializing-lazy-manytoone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!