Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Param and BodyParserEnginePost should be able to decode to Lists and arrays #87

Closed
tbroyer opened this issue Apr 9, 2013 · 2 comments
Closed
Milestone

Comments

@tbroyer
Copy link
Contributor

@tbroyer tbroyer commented Apr 9, 2013

Parameters can be multivalued (e.g. ?listbox=value1&listbox=value2 for a <select multiple> or a group of <input type=checkbox> with the same name), so they should be decoded into lists or arrays.

E.g. param1=1&param1=2 could be decoded into:

  • as an Arrays.asList("1", "2") into a List<String>, Collection<String> or Iterable<String> field/argument
  • as an ArrayList with values 1 and 2 into a List<Integer>, Collection<Integer> or Iterable<Integer> field/argument, and similarly for doubles, floats, longs and booleans.
  • as a String[] into a String[] or Object[] field/argument
  • as an int[] or Integer[], and similarly for doubles, floats, longs and booleans.

Open question: what to do with Object fields/arguments? getParameterMap uses a String[] for the values, so it could be used as-is; but List<String> also makes sense.
In #86 I added getParameterValues as a List<String>, so a List<String> would also make sense.

As for the implementation, a few APIs would have to change from Class<?> to Type or Guava's TypeToken to be able to capture the generic type parameters of fields/arguments.
I'd otherwise propose doing the above transformation within ParamParser (as an abstract class) or ParamParsers (as a helper method), so be used in both BodyParserEnginePost and ControllerMethodInvocation.

@raphaelbauer
Copy link
Contributor

@raphaelbauer raphaelbauer commented Apr 10, 2013

Makes really a lot of sense!
Do you think

  • we can still keep something like @param("myparam") String myParam in the controller => if there is only one myParam in the request? It seems a bit simpler than having Param("myparam") List myParam.
  • If you add the Lists it would be cool if the java doc clearly states the reason why there is a List and not only a single value (just copying the above issue is of course enough).
@raphaelbauer
Copy link
Contributor

@raphaelbauer raphaelbauer commented Dec 23, 2016

Fixed. Closing this one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants