How can I prevent Spring MVC from adding additional attributes to my JSON?
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
精彩评论