0

My requests look like:

http://...
  ?type[A].size=14
  &type[B].query=test

My @Controller has a method which should accept those generic request params:

@RequestMapping(...)
public void test(MyModel m) {
   ...
}

public static class MyModel {
  Map<String, ?> type;
}

The problem is: ? should be some class which is defined by the key of the Map.

This means: key=A should Map to class A and key=B should map to class B. According to the given request above: Class A will have a property int size and class B will have a property String query.

I just can't figure out, how I can tell Spring to use class A for key A and class B for key B.

(I know I could do it with POST and Jackson, but I'd like to solve this using a GET request).

Thanks for your help :)

Benjamin M
  • 23,599
  • 32
  • 121
  • 201
  • 1
    What you are expecting can not be easily achieved. You would have to write your own custom implementation. – shazin Sep 17 '14 at 05:46
  • Isn't it even possible to use something like `Map` where `MyContainer` simply accepts every possible key-value pair? **Btw:** `Map>` doesn't work, this would only accept `?type[A][size]=14`, but not `?type[A].size=14`. With this `Map` I could use Apache's `BeanUtils.populate` to copy all those properties to my desired class. – Benjamin M Sep 17 '14 at 06:09
  • First you must understand what Query String in a URL is. It is part of HTTP Protocol and multiple parameters consisting of only a single Key and a Value can be part of the Query String. Any complex structure you want to be passed must be handled in your controller code explicitly. – shazin Sep 17 '14 at 06:16
  • Of course I know what the query string is. The main "problem" with this is (for me): Jackson can do such things easily (using @JsonType), I thought: "Spring is broad and mighty and has a tool for (nearly) every use case, this must be in there". Every 6 month I find some missing feature in Spring `;)`, at least now I know that there will be no problems in the next half year `:)`. I think I'll just tell my frontend dev to change his code and use `?type[A][size]`. Thank you! – Benjamin M Sep 17 '14 at 06:32

0 Answers0