【问题标题】:Spring Adding Json Root Name at controller levelSpring在控制器级别添加Json根名称
【发布时间】: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);
        }
  }

【问题讨论】:

    标签: json spring


    【解决方案1】:

    在控制器级别创建条件 ObjectMapper 解决了这个问题。

    here is the solution

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-13
      • 2021-11-04
      • 2023-01-11
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多