【发布时间】:2011-09-29 14:25:33
【问题描述】:
我正在开发一个将 Jackson 用于 JSON 视图的 Spring MVC 应用程序。 假设我有两个类,如下所示。
class A {
String prop;
B other;
// getters setters
}
class B {
Integer id;
String name;
}
我要解决的是获取如下所示的 JSON 字符串。 对于 A 的完全初始化实例
{prop:"something", name:"otherthing"} // in here the class B
// is replaced with its propery name
插入
{prop:"something, other:{id:5,name:"otherthing"}}
注意:上面提到的两个类是 Hibernate 的实体类。 我已经使用@JsonIgnore 从 JSON 输出中消除了一些属性,是否可以 使用注解将子类替换为其属性?
【问题讨论】:
-
一个建议:“内部类”在标题中可能会产生误导,因为这实际上与 Java 内部类无关,而是与 JSON 结构的内联有关。但不确定什么是最适合轻松找到此问题的标题。
标签: json spring-mvc mapping jackson