如何防止 Spring MVC 添加额外的属性到我的 JSON 中?
我正在使用 Jackson 和 ContentNegotiatingViewResolver 从 Spring 控制器返回 JSON。
当我在 Spring 中定义这样的方法
public ModelMap save(FileUploadBean uploadItem, ParameterBean params) throws JsonParseException, JsonMappingException, IOException
并返回 ModelMap
ModelMap model = new ModelMap();
model.addAttribute("output","Save was ok");
return model;
时,Spring 总是将 uploadItem
和 params
附加到 JSON 响应,尽管我从未添加这些两个到 ModelMap。
结果看起来像这样
{
"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"
}
}
}
}
,这是默认行为吗?如果描述在哪里......
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"
}
}
}
}
Is this default behaviour, and if where is it described...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
面临类似的问题 -
查看以下链接。我发布了一个决议。
Spring JSON Jackson Marshaller 添加额外的我的响应对象中的参数
Faced a similar issue-
Check out the following link. I posted a resolution.
Spring JSON Jackson Marshaller adding additional parameter in my response object