0

I have a Java Spring API which expects 2 params, a simple String and a object:

@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

    }

I'm trying to send http GET request with Postman but I get this error, then I suppose that I'm not sending the data object paginationInfo in the correct way.

"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"

Since I can't change the way of sending, in fact must be GET and I have to use @RequestParam`, I don't know how to send JSON data in Postman parameters. I'm trying this and also other options but I always get error.

enter image description here

4
  • you can take second argument as a String and pass String to requestParam i postman And After getting it convert String to Object . Commented May 28, 2020 at 12:22
  • Ok but in this way i have to map from string to object in Java and i want a READY java object. Commented May 28, 2020 at 12:25
  • you have to pass it directly without json string. like argentName. pageSize = // pageNumber = // @MatteoBruni Commented May 28, 2020 at 12:26
  • Spring will bind it to PaginationInfoList class. @MatteoBruni Commented May 28, 2020 at 12:30

1 Answer 1

1

You can bind The request params to an object. In postman you will have 3 params ("agentName", "pageSize" and "pageNumber") and your controller will receive 2 objects

public ResponseEntity<ListResource> getList(@RequestParam("agentName") String agentName,
                                        @Valid PaginationInfoList paginationInfo)

http://dolszewski.com/spring/how-to-bind-requestparam-to-object/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.