我正在研究 Spring Rest 和 Angularjs。我对如何转换对象有疑问。假设我有两个类。
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "fooId", scope = Foo.class)
class Foo {
int fooId;
String fooName;
String fooTitle;
Bar bar;
}
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "barId", scope = Bar.class)
class Bar {
int barId;
String barName;
String barTitle;
int fooId;
}
当我将 Foo 对象和 Bar 发送到 Angularjs 时,我得到如下内容:
{
"fooId": 1,
"fooName": "foo-name",
"fooTitle": "foo-title",
"bar": 1
}
我本来希望得到这样的结果:
{
"fooId": 11,
"fooName": "foo-name",
"fooTitle": "foo-title",
"bar": {
"barId": 22,
"barName": "bar-name",
"barTitle": "bar-title",
"fooId": 11
}
}
可能出了什么问题?
最佳答案
尝试从 Bar 类中删除 @JsonIdentityInfo 注释 - 默认的其余 Controller 在没有它的情况下可以很好地转换类!
关于java - Spring Rest JSON 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34522846/