【发布时间】:2020-09-15 18:12:57
【问题描述】:
我有一个 Java Spring API,它需要 2 个参数,一个简单的字符串和一个对象:
@RequestMapping(value = "list", method = RequestMethod.GET)
public ResponseEntity<ListResource> getList(@RequestParam("agentName") String agentName,
@RequestParam("paginationInfo") PaginationInfoList paginationInfo {
//After http request i expect to have here my java Object PaginationInfoList ready to use
}
我正在尝试使用 Postman 发送 http GET 请求,但出现此错误,然后我想我没有以正确的方式发送数据对象“paginationInfo”。
"Failed to convert value of type 'java.lang.String' to required type 'com.pippo.prova.test.model.in.PaginationInfoList'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.pippo.prova.test.model.in.PaginationInfoList': no matching editors or conversion strategy found"
由于我无法更改发送方式,事实上必须是 GET 并且我必须使用@ReuqestParam,我不知道如何在 postman 参数中发送 json 数据。我正在尝试这个以及其他选项,但总是出错。
【问题讨论】:
-
您可以将第二个参数作为字符串并将字符串传递给 requestParam i postman 并在得到它之后将 String 转换为 Object 。
-
好的,但是通过这种方式,我必须在 Java 中从字符串映射到对象,并且我想要一个 READY java 对象。
-
你必须直接传递它而不用json字符串。喜欢
argentName。pageSize= //pageNumber= // @MatteoBruni -
Spring 会将其绑定到
PaginationInfoList类。 @MatteoBruni
标签: java json spring-boot api postman