users@jersey.java.net

Optional JAXB Parameters

From: Jonathan Holloway <jonathan.holloway_at_gmail.com>
Date: Thu, 13 Aug 2009 13:32:38 -0700

Hi,

Please excuse the silly example, but I'm wondering whether it's possible to
have JAXB annotated objects that are optional with Jersey/JAX-RS.
In the example below I have an animal object which I bind to based on the
XML present in the body of the POST request.

   @POST
    @Consumes(MediaType.APPLICATION_XML)
    @Path("/{name}")
    public Response getSummary(Animal animal,
            @PathParam(MessageConstants.NAME_PARAM) final String name
@DefaultValue("none")

However, what I want to do is to be able to cope with the body not
containing an XML block. In this case I don't want it to attempt to find a
reader for
Animal, it would be great if I could just have it construct an empty Animal
instance using the default constructor. At present this fails with:

A message body reader for Java type, class com.test.Animal and MIME media
type, application/octet-stream, was not found

Is there a way to do this?

Many thanks,
Jon.