Hi

It is only possible to avoid having @XmlRootElement on the trunk.
> jp.setJaxbElementClassNames(list);

This property affects the serialization of objects of
@XmlRootElement-annotated types.
I've added a jaxbElementClassMap property which provides the info (className
- elementName) needed when creating JAXBElements.

> Warning : .No message body writer found for response class : Customer.

I'll need to update JAXB/JSON providers to return true in isReadable() if no
@XmlRootElement is available but jaxbElementClassMap is (with a given class
name being the key).

If you wish you can register a custom JSON provider - copy/paste the
existing trunk code into your own custom provider and also update isReadable
as suggested above - and it will work with 2.2.3... 
  
cheers, Sergey

Sam.Wang wrote:
> 
> Hi Sergey:
> 
> I am trying to test it in version 2.2.3, but there are still some errors.
> 
> 2009-8-11 10:58:55 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor
> writeResponseErrorMessage
> Warning : .No message body writer found for response class : Customer.
> 
> 
> Following is my demo code , could you tell me how to do that? 
> 
>               JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>                 ....
>               JSONProvider jp = new JSONProvider();
>               List<String> list = new ArrayList<String>();
>               list.add("Customer");
>               jp.setJaxbElementClassNames(list);
> 
>               sf.setProvider(jp);
> 
> 
> 
> //the @XmlRootElement annotation is removed as testing.
> public class Customer {
>     private long id;
>     private String name;
>     ....
> }
> 
> 
>       @GET
>       @Path("/customers/{id}/")
>       public Customer getCustomer(@PathParam("id") String id) {
>               long idNumber = Long.parseLong(id);
>               Customer c = customers.get(idNumber);
>               return c;
>       }
> 
> Is there anything I made wrong? Thanks.
> 
> 
> Sergey Beryozkin wrote:
>> 
>> I have just updated JAXBElementProvider to properly wrap into
>> JAXBElements those JAXB-generated types
>> which are missing for whatever reasons @XmlRootElement annotations.
>> 
>> 'jaxbElementClassNames' list property I referred to earlier can only be
>> used with classes which do have @XmlRootElement annotations, it is really
>> only useful if the serialization of the derived types needs to be
>> affected.
>> 
>> I've added a similar jaxbElementClassMap property which contains
>> className to element name pairs, with element names being either simple
>> names or expanded qnames.
>> If an object class has no @XmlRootElement but its name is a key in this
>> map then JAXBElement will be created internally and serialized properly.    
>> 
>> I think it can be quite useful in a number of cases.
>> 
>> Scott - if you need this feature right now then let me know please and I
>> can help you to create a custom JAXBElementProvider which will do it for
>> you, till the fix makes it into the next 2.2.x release.
>> 
>> thanks, Sergey
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/%40XmlRootElement-with-jax-rs-jax-ws-tp24795823p24913237.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to