users@jersey.java.net

Re: [Jersey] Trying to use JAXB _at_Xml.. with interfaces

From: Kevin Duffey <andjarnic_at_yahoo.com>
Date: Wed, 1 Oct 2008 21:57:41 -0700 (PDT)

Not sure this will solve your problem, but if you're using @ConsumeMime instead of @Consumes, I am guessing you're using a .8 or earlier version. Perhaps you should grab the latest and try it out since it's pretty much the 1.0 final that is due soon. Sorry if it doesn't help with your problem.




----- Original Message ----
From: Alex Sherwin <alex.sherwin_at_acadiasoft.com>
To: Jersey Users <users_at_jersey.dev.java.net>
Sent: Wednesday, October 1, 2008 6:30:38 PM
Subject: [Jersey] Trying to use JAXB @Xml.. with interfaces

This is killing me, I've been following the code examples found at
https://jaxb.dev.java.net/guide/Mapping_interfaces.html regarding techniques
to use with JAXB to allow the usage of interfaces/abstract classes with JAXB
marshalling/unmarshalling.

I can get this to work with straight marshall/unmarshall calls, however when
I try to use it with a JAX-RS Jersey service like the following:

  @PUT
  @ConsumeMime({ "application/xml", "java/object" })
  @ProduceMime({ "application/xml", "java/object" })
  public void sendNew(final ConduitDemand demand) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Got Demand [" + demand + "]");
    }
  }

Where ConduitDemand is an interface, AbstractConduitDemandBase is an
abstract base impl, and ConduitDemand1 is an actual impl class. No matter
what combination I try, I can never have any success unless I relegate to
directly using the impl class ConduitDemand1 as the arg in the JAX-RS
resource.

I've tried creating an XmlAdapter class on each of the
AbstractConduitDemandBase and ConduitDemand1 classes, either with one or the
other, or both.. and every combination I can think of, but I always get one
of the following errors:

- ConduitDemand is an interface, and JAXB can't handle interfaces.
- A message body reader for Java type, interface ConduitDemand, and MIME
media type, application/xml, was not found

I've also gotten the same error for ConduitDemand1 (this was resolved by
adding an @XmlRootElement(name="demand") annotation to the empty
ConduitDemand1 class, which extends the Abstract class which has the same
@XmlRootElement(name="demand") annotation on it


Anyone know of a way I can use an interface in the JAX-RS service resources?

Alex Sherwin
alex.sherwin_at_acadiasoft.com





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net