users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 02 Oct 2008 09:42:38 +0100

HI Alex,

When using JAXB for processing request bodies the unannotated
parameter of the resource method needs to have enough information such
that the JAXB unmarshalling functionality can be selected.

The trigger for using JAXB s when the parameter class is annotated
with @XmlRootElement or @XmlType, or the type is JAXBElement<T>. Then
of course that type needs to be supported when unmarshalling. Note
that as Kevin suggests using the latest version, 1-0-ea-SNAPSHOT,
would be best, but you will still get the same result as you do now.

When you got this to work with straight marshall/unmarshall what Java
types were you referring to in the unmarshal and marshal methods? can
you send some example code?

Paul.


On Oct 2, 2008, at 2:30 AM, Alex Sherwin wrote:

> 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
>