We are using Spring Boot to build rest api, I am facing issue in @PathVariable in Spring Boot rest api. It is not accepting trialing whitespace in path parameter in the URL.
This URL works:
https://foo.com/api/v1/pen/?param1=foobar
But below url doesn't work, and it removes trailing whitespace:
https://foo.com/api/v1/pen /?param1=foobarfoo
Yes, it may look strange but we have requirements as this api does lot of database search and even whitespace with without whitespace affects the output. This is how my Request Mapping looks like:
@RequestMapping(value="api/v1/{sentenceToSearch}",method=RequestMethod.GET,produces={MediaType.APPLICATION_JSON})
I searched many questions in stackoverflow like:
Controller Pathvariable bind removes ending space
But above question doesn't have solution. Also tried various questions which was having query to prevent trimming of "." from url and based on that I tried to add below code:
@Configuration
protected static class AllResources extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer matcher) {
matcher.setUseRegisteredSuffixPatternMatch(true);
}
}
But it works for "." not for special characters, also I tried adding expression like this in request mapping: {sentenceToSearch:.+}
but all of them not working.
Can someone help me in this?