不要在JSON中显示地图条目

时间:2016-05-23 15:53:38

标签: json spring rest

我有以下端点:

@RestController
@RequestMapping(value = "/info")
public class InfoEndPoint {

....

    @Autowired
    public InfoEndPoint(....) {
        ....
    }

    @RequestMapping(method = RequestMethod.GET)
    public Info get(final HttpServletRequest httpServletRequest) {
        ...
        return info;
    }

}

info对象如下:

public class Info {

    private App app;

    public App getApp() { return app; }
    public void setApp(final App app) { this.app = app; }
}

public class App {

    @JsonUnwrapped
    private Map<String, String> map;

    public App() { map = new HashMap<>(); }

    public Map<String, String> getMap() { return map; }
    public void setMap(final Map<String, String> map) { this.map = map; }
}

当我呼叫其余端点时,响应如下:

{
  "app": {
    "map": {
      "description": "Unity-web",
      "name": "Unity"
    }
  }
}

但是,我想删除地图条目,并有此回复

{
  "app": {
    "description": "project",
    "name": "project"
  }
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

此处描述了解决方案Why I'm not able to unwrap and serialize a Java map using the Jackson Java library?

基本上它涉及调用@JsonAnyGetter