2

If I use the "{}" to specify the count condition in the regular expression of JAX-RS @Path, eclipse throws as error.

@Path("/apps/{itemId:\\d{10}}")
public Response getItems(...

The @Path annotation value '/apps/{itemId:\d{10}}' is invalid: missing '{' or '}'.

Is above JAX-RS Path not a valid path ? Is it due to eclipse JAX-RS validator problem ? If I just specify @Path("/apps/{itemId}") there is no error.

ulab
  • 1,079
  • 3
  • 15
  • 45

1 Answers1

2

You can't use curly brackets inside variable when using regex in Path annotation. Use instead:

@Path("/apps/{itemId: \\d+}")

regex = *( nonbrace / "{" *nonbrace "}" ) ; where nonbrace is any char other than "{" and "}"

Theoretically you can check 10 digits as you want using multiple [0-9]:

@Path("/apps/{itemId: [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]}")
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • it is strange that '{' is not accepted. I would rather accept all digits and validate after that. Thanks. – ulab Apr 08 '19 at 15:00
  • @ulab they probably wanted to avoid handling special cases with inner/multiple curly braces – Ori Marko Apr 08 '19 at 15:02