[英]JSONObject as request body in Spring mvc with jersey(jackson)
I recently got to know that Jackson mapper can not get you a JSONObject into your code.我最近了解到 Jackson 映射器无法将 JSONObject 放入您的代码中。 Most of the time I have used custom POJOs to get the request body so this was surprising to me.大多数时候我使用自定义 POJO 来获取请求主体,所以这让我感到惊讶。 Please excuse if this is a naive question.如果这是一个天真的问题,请原谅。
public Response anyPOSTApi( @RequestBody org.json.JSONObject json) {...}
If you try the above code, you would get an empty JSONObject always.如果您尝试上面的代码,您将始终得到一个空的 JSONObject。
I would like to know the reason behind this (Do not need a workaround as of now)?我想知道这背后的原因(目前不需要解决方法)? Or is there any specific dependency to get this working?或者是否有任何特定的依赖关系可以使它正常工作?
@RequestBody maps body data to method arguments only if argument class fields name is matching to keys of query in request body. @RequestBody 仅当参数 class 字段名称与请求正文中的查询键匹配时,才将正文数据映射到方法 arguments。 Otherwise u have to register your Own DataBinder using @initBinder annotated method which will bind request body data to your argument.否则,您必须使用 @initBinder 注释方法注册您自己的 DataBinder,该方法会将请求正文数据绑定到您的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.