I'm using annotation javax.validation.constraints.Pattern to validate the sort parameter. The value of this parameter must be: +id or +originId for ascending, and -id or -originId for descending.
The syntax of this parameter can not be modified.
@Valid @Pattern(regexp= SORT_REGEXP, message = SORT + NOT_VALID) @RequestParam(name = SORT, required = false) String sort, This is what I have as my regular expression:
^[+-]id$|^[+-]originId$ I have also tried escaping the plus sign + like:
^[\\+-]id$|^[\\+-]originId$ If I use the -id or the -originId, it's been validated but when I use the + it says that it's not matching the pattern.
How to match the plus-sign with a regular expression?
ascanddescinstead of mathematical signs: Spring Data Rest - Sort by multiple properties - Stack Overflow+is usually decoded to space: url - Why is Spring de-coding + (the plus character) on application/json get requests? and what should I do about it?. See also "Requires URL percent encoding" for Lucene-syntax in Paging, sorting, filtering and retrieving specific fields in your RESTful API | by Guillaume Viguier-Just | Medium