内部类的自定义Jackson映射
问题内容:
我正在开发一个使用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的Entity类。我已经使用@JsonIgnore从JSON输出中消除了一些属性,是否可以通过注释用其属性替换子类?
问题答案:
除了使用自定义序列化程序外,这还不可能,尽管有一个功能请求(http://jira.codehaus.org/browse/JACKSON-132)可能会在Jackson
1.9中实现(因为它的投票数相对较高,意味着一些用户确实希望看到它的实施)。