hgoebl / DavidWebb

Lightweight Java HTTP-Client for calling JSON REST-Services (especially for Android)
https://hgoebl.github.io/DavidWebb/
MIT License
127 stars 41 forks source link

changed Request.params to hold a list of pairs instead of a map #15

Closed itaisanders closed 8 years ago

itaisanders commented 9 years ago

changed Request.params to hold a list of pairs instead of a map to allow multiple occurrences of the same parameter key with different values.

itaisanders commented 9 years ago

I allowed myself to tweak a quick fix for my issue about the same-key parameters. I tested it on our own code and everything seems to work fine. I tried to retain the backwards compatibility so the change will not conflict with any code using this library, just in case you decide to accept it into the core branch. I can testify that this version ran on our old code without any problem or external fix.

itaisanders commented 9 years ago

one more thing: I fixed the tests so there is no error, but I didn't run these tests myself, only our own tests of the code using the library.

itaisanders commented 9 years ago

again - tested on our code and works fine with no external changes.

hgoebl commented 9 years ago

Of course you're right that there should be support for multi-value parameters. But with the given API there is still a problem handling this edge case. Until now, setting and overwriting a parameter by calling req.param("x", 1) and then req.param("x", 2) overwrites the value. It's also stated in the docs that one can overwrite existing parameter values. So changing the current interface semantics is not the best option.

Options how this could be solved:

  1. Add an option like enableMultiValuedParams(true) (default: false) or multiValues() and only then change semantics of req.param().
  2. Handle multi-valued params with Collection and [] as param value in req.param(name, value)
hgoebl commented 8 years ago

Thanks for your contribution, but I've implemented in a way it remains compatible with old code.

You can now either call request.multipleValues() and then multiple times param(name, value) or just request.param("name", Arrays.asList("orange", "apple", "banana"))

I hope this helps. If not, you can always use your own fork/branch - it's MIT licensed.