【发布时间】:2015-12-30 04:20:46
【问题描述】:
我正在研究 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;
}
当我将带有 Bar 的 Foo 对象发送到 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
}
}
可能出了什么问题?
【问题讨论】:
-
无法产生您使用
spring 4.2.1.RELEASE和jackson-databind 2.4.4获得的结果。我得到了预期的结果。使用 Chrome Rest Client 进行测试
标签: java angularjs json spring rest