java - Spring Rest JSON 转换

标签 java angularjs json spring rest

我正在研究 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/

相关文章:

javascript - 对于给定的正则表达式,R 正则表达式编译器的工作方式不同

android - Cordova geolocation watchPosition frequency is higher the options allow it

Java - 从 JSON 中提取数组字符串并转换为 JSON 格式

java - 基本单词的拼写检查

java - 如何创建批处理文件并使用参数执行 jar 文件

java - 当 JTextField 达到一定数量的字符时,它会移动到下一个字符

javascript - 共享http库

css - ng-enter 动画期间出现不需要的滚动

javascript - 由于 JSON 对象中的 $promise 和 $resolved,ngResource PUT 返回错误请求

Android SSL - 无对等证书 (GeneXus)