2
我使用Spring 3.2和我的Spring MVC控制器生成JSON数据(与杰克逊数据绑定-2.2.0)。我想用@JsonRootName(com.fasterxml.jackson.annotation.JsonRootName)注释来定制我的JSON根名称,但是,我无法弄清楚如何使用Spring配置来启用它。如何启用@JsonRootName在春天mvc 3.2
@JsonRootName("rootNameTest")
public class MyModel {
private String prop;
public String getProp() {
return prop;
}
public void setProp(String prop) {
this.prop = prop;
}
}
这里是我的设置在sevlet-context.xml中
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
<bean class="org.springframework.web.accept.ParameterContentNegotiationStrategy">
<constructor-arg>
<map>
<entry key="json" value="application/json"/>
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>
</list>
</property>
</bean>
请帮助。谢谢。