users@jersey.java.net

[Jersey] Re: JAXB _at_XmlSeeAlso supported in Jersey?

From: Arul Dhesiaseelan <aruld_at_acm.org>
Date: Wed, 9 Nov 2011 12:56:46 -0700

Hi Jakub,

Sorry for the confusion. I was wondering if XmlJavaTypeAdapter could be
supported in addition to XmlSeeAlso as well. Anyway, I have logged a
request http://java.net/jira/browse/JERSEY-829

I have attached a self-contained project (no JAXWS) to the JIRA, uses
vanilla JAXB confirming interfaces and abstract classes work using JAXB
hints and a JAXRS test case which fails to honor them.

Let me know if this helps.

Thanks!
Arul

On Wed, Nov 9, 2011 at 9:52 AM, Jakub Podlesak <jakub.podlesak_at_oracle.com>wrote:

> **
> Hi Arul,
>
> I am confused. You started with a JAX-RS use case using
> an interface annotated with @XmlSeeAlso.
>
> Now your example uses JAX-WS and @XmlJavaTypeAdapter annotated interface.
>
> Could you please clarify?
>
> The best would be to file a RFE and attach JAX-RS based use cases.
> We can further discus there.
>
> Thanks,
>
> ~Jakub
>
>
> On 8.11.2011 19:54, Arul Dhesiaseelan wrote:
>
> Hi Jakub,
>
> Sure. I abstracted out a simple project (basically a CXF JAXWS sample)
> that shows interfaces works with JAXB adapters.
>
> Attaching it as a maven project. Run the Server and run the Client code
> and it should work just fine.
>
> Do you think this can be supported in Jersey? I can log an enhancement
> request with a similar JAX-RS sample.
>
> Let me know.
>
> Thanks!
> Arul
>
> On Tue, Nov 8, 2011 at 10:48 AM, Jakub Podlesak <jakub.podlesak_at_oracle.com
> > wrote:
>
>> Hi Arul,
>>
>> this is currently not supported as Jersey only
>> recognizes @XmlRootElement or @XmlType annotated types
>> as the types to be processed by the JAXB entity providers.
>> If JAXB supports your scenario (i mean unmarshaling a concrete
>> implementation when i ask for the interface) out of the box,
>> it should be quite easy to add this feature. Could you please
>> confirm that this is the case?
>>
>> Then also, would you be so kind, file a new RFE (at [1]) and attach a
>> simple
>> project, which we could use as a test case for the expected behavior?
>>
>> That should help us to bring this feature for you.
>>
>> Thanks,
>>
>> ~Jakub
>>
>> [1]http://java.net/jira/browse/JERSEY
>>
>>
>> On 8.11.2011 18:37, Arul Dhesiaseelan wrote:
>>
>>> I have the following resource methods:
>>>
>>> @POST
>>> @Path("join")
>>> @Consumes(MediaType.APPLICATION_XML)
>>> public void processJoinNotificationFromPeer(JoiningNotification
>>> notification) {
>>> notifications.add(notification);
>>> }
>>>
>>> @POST
>>> @Path("leave")
>>> @Consumes(MediaType.APPLICATION_XML)
>>> public void processLeaveNotificationFromPeer(LeavingNotification
>>> notification) {
>>> notifications.add(notification);
>>> }
>>>
>>> private final List<PeerNotification> notifications = new
>>> ArrayList<PeerNotification>();
>>>
>>> Ideally, I would like to merge these two methods into one:
>>>
>>> @POST
>>> @Path("notify")
>>> @Consumes(MediaType.APPLICATION_XML)
>>> public void processNotificationFromPeer(PeerNotification notification) {
>>> notifications.add(notification);
>>> }
>>>
>>> But, this does not work because PeerNotification is an interface. I have
>>> annotated the interface as shown below:
>>>
>>> @XmlSeeAlso({JoiningNotification.class, LeavingNotification.class})
>>> public interface PeerNotification {
>>> Peer getPeer();
>>> }
>>>
>>> This is supposed to bind the implementations at JAXB runtime, but looks
>>> like this does not work. Is this supported in Jersey?
>>>
>>> Also, I have a generic API which returns List of PeerNotifications, but
>>> this also suffers from the same problem.
>>>
>>> @GET
>>> @Path("notifications")
>>> @Produces(MediaType.APPLICATION_XML)
>>> public List<PeerNotification> getNotifications() {
>>> return notifications;
>>> }
>>>
>>>
>>> SEVERE: A message body writer for Java class java.util.ArrayList, and
>>> Java type java.util.List<fluximpl.cluster.events.PeerNotification>, and
>>> MIME media type application/xml was not found
>>> Nov 8, 2011 10:26:21 AM com.sun.jersey.spi.container.ContainerResponse
>>> write
>>> SEVERE: The registered message body writers compatible with the MIME
>>> media type are:
>>> application/xml ->
>>> com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App
>>> com.sun.jersey.core.impl.provider.entity.DocumentProvider
>>> com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
>>> com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
>>> com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App
>>> */* ->
>>> com.sun.jersey.core.impl.provider.entity.FormProvider
>>> com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
>>> com.sun.jersey.core.impl.provider.entity.StringProvider
>>> com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
>>> com.sun.jersey.core.impl.provider.entity.FileProvider
>>> com.sun.jersey.core.impl.provider.entity.InputStreamProvider
>>> com.sun.jersey.core.impl.provider.entity.DataSourceProvider
>>> com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
>>> com.sun.jersey.core.impl.provider.entity.ReaderProvider
>>> com.sun.jersey.core.impl.provider.entity.DocumentProvider
>>> com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
>>> com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
>>> com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
>>> com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
>>>
>>>
>>> I have tried few other things using XmlAdapter, but none of them work.
>>> Sounds like, this is supported in Resteasy (
>>> http://209.132.183.68/docs/en-US/JBoss_Enterprise_Web_Platform/5/html/RESTEasy_Reference_Guide/JAXB_INTERFACES.html
>>> ).
>>>
>>> Am I missing anything here? I am using Jersey 1.10. Appreciate your
>>> suggestions.
>>>
>>> Thanks!
>>> Arul
>>>
>>
>
>