【发布时间】:2016-03-07 17:02:00
【问题描述】:
有没有办法在@controller 级别而不是在应用程序级别添加根元素。我需要以下格式的回复
{"BaseResponse":{"HeaderResponse":{"prop1":"test","prop2":"1"},"DetailResponse":[{"recordDesc":"record1","recordId":1},{"recordDesc":"record1","recordId":1}]}}
但我没有在根目录下获得“BaseResponse”
{"HeaderResponse":{"prop1":"test","prop2":"1"},"DetailResponse":[{"recordDesc":"record1","recordId":1},{"recordDesc":"record1","recordId":1}]}
我不想在应用程序级别配置 WRAP_ROOT_VALUE,如下所示。
public class SpringMVCJacksonObjectMapper extends ObjectMapper
{
public SpringMVCJacksonObjectMapper()
{
super();
this.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
this.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
}
}
【问题讨论】: