0

I have to pass a 2d integer array to get REST call.

Example:[[1,2,3], [5,10,11]]

I can pass it by entering data separately into the parameter like

Example: http://localhost:1136/demo?x=3,4,5&x=10,11,12

But I want it to be like

?x=[[1,2,3], [5,10,11]]

Any suggestion

Anil
  • 133
  • 1
  • 8

1 Answers1

2

You can define a @RequestParam(value= "x") String[][] like this:

@GetMapping(value = "/demo")
public void demo(@RequestParam(value= "x") String[][] array2d) {
    // You will get: array2d = [[3,4,5],[10,11,12]]
}

Note: You may get the valid characters are defined in RFC 7230 and RFC 3986 error.

You can add to application.properties file something like this:

tomcat.relaxed-query-chars="|,{,},[,]"
İsmail Y.
  • 3,579
  • 5
  • 21
  • 29
  • I defined it in the same way. But unable to pass in request call as I mentioned above. java.lang.IllegalArgumentException: Invalid character found in the request-target. The valid characters are defined in RFC 7230 and RFC 3986 – Anil Mar 01 '21 at 08:16
  • Do you want to send a request `../demo?x = [[1,2,3], [5,10,11]]`? – İsmail Y. Mar 01 '21 at 11:06
  • yes. Similar to the above or ?x={ {1,2,3}, {5,10,11} } – Anil Mar 02 '21 at 12:03
  • I added the error that will fix your `The valid characters are defined in RFC 7230 and RFC 3986` error as a note. It will be quick and easy to run your request as in the example. If you do not have the possibility to do this and **you will need to obtain the value with `@RequestParam (value =" x ") String array2d` and process it manually.** – İsmail Y. Mar 02 '21 at 13:24
  • 1
    Thanks, it works for me. I have added these properties to the application.properties file. server.tomcat.relaxed-path-chars=[, ] server.tomcat.relaxed-query-chars=[, ] – Anil Mar 03 '21 at 08:37