Issue
I have a REST Component in Spring. Simplified, it looks like this:
@RequestMapping(value = "/route", method = RequestMethod.GET)
public Object thisIsTheMethod(@RequestParam(value = "value", required = false) List<String> values) {
return OtherClass.doTheThing(values);
}
This is used to consume a list of Strings of arbitrary length. You could do it a number of ways:
localhost:8080/route?value=this&value=that
OR
localhost:8080/route?value=this,that
Now let's say I want to pass in one string which contains a comma: value,1
. How would I go about doing that? Replacing the comma with %2C results in a list of 2 values ("value", "1"). Putting anything in quotes, or escaped quotes, has similar problems. It looks like it works when I have multiple parameters and use the multiple-values pattern, though not when I use the comma-separated pattern.
Solution
You can set your Delimiter
. The comma is just the default one used in org.springframework.boot.convert.DelimitedStringToCollectionConverter
when it isn't set. If you wish, you can disable the Delimiter
completely. For your code, it would look like this:
import org.springframework.boot.convert.Delimiter;
@RequestMapping(value = "/route", method = RequestMethod.GET)
public Object thisIsTheMethod(@Delimiter(Delimiter.None) @RequestParam(value = "value", required = false) List<String> values) {
return OtherClass.doTheThing(values);
}
Answered By - Grez
Answer Checked By - Senaida (JavaFixing Volunteer)