2

There are multiple annotations in JAX-RS method params: @QueryParam, @PathParam, etc. https://docs.oracle.com/cd/E19798-01/821-1841/6nmq2cp1v/index.html

However, these annotations are not mandatory. I have a situation when a parameter of GET method is not annotated:

  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Map<String, Object> getProduct(
      String domain,
      @QueryParam("code") String code,
      @QueryParam("region") String region
  ) {

Here domain parameter is not annotated at all. I’m not sure what it means. (It is a production code from some repository).

For POST methods this would mean that domain parameter would consume request body: How to get full REST request body using Jersey?

But what it would mean for GET method? As far as I know body does not make much sense for GET requests (i.e., it can be safely ignored according to web standard).

What is the default fallback for unannotated parameters? I did not find the answer in documentation.

dimnnv
  • 678
  • 3
  • 8
  • 21
  • Did you try it to see what happens? – Paul Samsotha Dec 23 '22 at 17:59
  • This was the production code that I’ve encountered in one of work projects. In theory I could simplify, run and debug it, but regardless of result, I still want to find some sort of ‘official confirmation’ of how it should work (e.g. documentation reference). – dimnnv Dec 23 '22 at 22:29
  • I can tell you that on the Jersey client side, when you try to send a GET request with a body, you get an "HTTP non-compliance error". I forgot on the server side, but there might have been a warning if not an error. Other implementations might be different. The semantics of the non-annotated parameter is always to be the body. – Paul Samsotha Dec 24 '22 at 20:10

1 Answers1

2

This is definitely a corner case due to the fact that HTTP specification (RFC 2616 at least) does not explicitly forbid a body being present in a GET request.

On the other hand, JAX-RS (JSR311) is very specific in 3.3.2.1:

The value of a non-annotated parameter, called the entity parameter, is mapped from the request entity body. Conversion between an entity body and a Java type is the responsibility of an entity provider, see section 4.2.
Resource methods MUST NOT have more than one parameter that is not annotated with one of the above- listed annotations.

So, to finally answer your question: Assuming your implementation accepts a GET request with a body (highly unlikely, based on my experience), JAX-RS should try to read it into the domain parameter.

However, I'd expect that domain would be null, since GET requests don't usually have a body, so with proper null handling of the parameter, this behavior can easily go undetected.

Tasos P.
  • 3,994
  • 2
  • 21
  • 41