I have the following method declared in my resource class.
@Path("{id:\\d+}")
@PUT
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response putPerson(@PathParam("id") long id, Person person) {
logger.debug("Going to update the person with id: {} to name {} age {} and salary {}", id, person.getName(), person.getAge(), person.getSalary());
db.put(id, person);
return Response.noContent().build();
}
Here I understand that my {id} path value does get injected in the id parameter due to the @PathParam annotation. But I am curious how does the input media declared by the @Consumes annotation get injected in the person parameter? I am wondering because there are no annotation declared to inject any value into the person parameter.
I know that the media does get injected because my logger statement does print the correct values.
Is this inject process documented somewhere in the Jersey user manual or any JavaDocs?
I did find the answer in the Jersey User Guide for version 2.31 release in section 7.1. It reads the following.
Unlike method parameters that are associated with the extraction of request parameters, the method parameter associated with the representation being consumed does not require annotating. In other words the representation (entity) parameter does not require a specific 'entity' annotation. A method parameter without an annotation is an entity. A maximum of one such unannotated method parameter may exist since there may only be a maximum of one such representation sent in a request.