4

I have looked at the various answers and they do not resolve my issue. I have a very specific client need where I cannot use the body of the request.

I have checked these posts:

Note: I do encode the URI.

I get various errors but illegal HTML character is one. The requirement is quite simple:

Write a REST service which accepts the following request

GET /blah/bar?object=object11&object=object2&...

object is a POJO that will come in the following JSON format

{
    "foo": bar,  
    "alpha": {       
        "century": a,
    }
}

Obviously I will be reading in a list of object...

My code which is extremely simplified... as below.

 @RequestMapping(method=RequestMethod.GET, path = "/test")
 public Greeting test(@RequestParam(value = "object", defaultValue = "World") FakePOJO aFilter) {
     return new Greeting(counter.incrementAndGet(), aFilter.toString());
 }

I have also tried to encapsulate it as a String and convert later which doesnt work either.

Any suggestions? This should really be extremely simple and the hello world spring rest tut should be a good dummy test framework.

---- EDIT ----

I have figured out that there is an underlying with how jackson is parsing the json. I have resolved it but will be a write up.. I will provide the exact details after Monday. Short version. To make it work for both single filter and multiple filters capture it as a string and use a json slurper

GvD
  • 63
  • 2
  • 6
  • "I have also tried to encapsulate it as a String and convert later which doesnt work either" - why doesn't work? –  Nov 06 '18 at 09:19
  • 2
    Possible duplicate of [JSON parameter in spring MVC controller](https://stackoverflow.com/questions/21577782/json-parameter-in-spring-mvc-controller) –  Nov 06 '18 at 09:21
  • The error when encoding: java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol – GvD Nov 09 '18 at 01:27

1 Answers1

2

If you use @RequestParam annotation to a Map<String, String> or MultiValueMap<String, String> argument, the map will be populated with all request parameters you specified in the URL.

 @GetMapping("/blah/bar")
 public Greeting test(@RequestParam Map<String, String> searchParameters) {
     ...
 }

check the documentation for a more in depth explanation.

aurelius
  • 3,946
  • 7
  • 40
  • 73