开发者

How can I prevent Spring MVC from adding additional attributes to my JSON?

开发者 https://www.devze.com 2023-04-06 09:26 出处:网络
I am using Jackson and a ContentNegotiatingViewResolverto return JSON from Spring controllers. When I define a method in Spring like this

I am using Jackson and a ContentNegotiatingViewResolver to return JSON from Spring controllers.

When I define a method in Spring like this

public ModelMap save(FileUploadBean uploadItem, ParameterBean params) throws JsonParseException, JsonMappingException, IOException

and return a ModelMap

ModelMap model = new ModelMap();
model.addAttribute("output","Save was ok");
return model;

Spring allways attaches uploadItem and params to the JSON response despite I have never added these two to ModelMap.

The result looks something like that

{
  "parameterBean": {
    "values": {
      "json": "{\"seizure\":{\"id\":1},\"classDocumentType\":{\"id\":1},\"seizureDocumentI18ns\":[{\"id\":\"\",\"comment\":\"123\",\"matLanguageCode\":\"\"}]}"
    }
  },
  "output": ["Save was ok"],
  "fileUploadBean": {
    "file": {
      "originalFilename": "Form.png",
      "fileItem": {
        "contentType": "image/png"
      }
    开发者_JS百科}
  }
}

Is this default behaviour, and if where is it described...


Faced a similar issue-

Check out the following link. I posted a resolution.

Spring JSON Jackson Marshaller adding additional parameter in my response object

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号