杰克逊映射器写入id而不是整个对象 [英] Jackson mapper write id instead of entire object
问题描述
我使用jackson 2.4.2来编写一些hibernate结果,因为hibernate对象可能相当复杂,我收到的问题是,我有一个hibernate对象列表,其中一些可能引用同一个对象,因此,jackson只对对象进行一次mapp,而所有其他对象只被映射为id。我不希望它表现得像这样,并且希望它将对象写为对象,无论它是否在其他对象中进行解析。
I am using jackson 2.4.2 to mapp some hibernate results, because the hibernate object can be quite complex, the problem I am receiving is, I have a list of hibernate object, some of them may refer to the same object, thus jackson only mapp the object once, and all other objects are only mapped as an id. I don't want it behave like this and want it to write objects as object no matter if it is parse in other object or not.
推荐答案
向我们展示一些代码,特别是你的类结构和json / xml或其他结果。
Show us some code and especially your class structure and json/xml or whatever results.
但我认为问题是你只是将object_id保存为Integer而不是作为对象。
But i think the problem is that you are only saving object_id as Integer and not as object.
错误:
public class Foo {
private String name;
private Integer foo_id;
}
正确:
public class Foo {
private String name;
private Foo foo;
}
这篇关于杰克逊映射器写入id而不是整个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!