users@jaxb.java.net

Re: Generalized JAXB container class?

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 28 Feb 2012 08:07:06 +0100

Given a DOM tree, any (un)marshalling you can define in terms of
mappings of an XPath to some java.lang.Class and the relation between
the element's children to the proeprties of the class is feasible. It's either
out of the box (using javax.xml.bind.annotation..*) or some binding
feature, or one of the plugins.

Honestly, I don't quite see what you'd like to have. Can you formulate
it in terms of JAXB/XML Schema/XML alone, leaving Jersey aside?

-W


On 27/02/2012, msummers <msummers57_at_gmail.com> wrote:
>
>
> Is there a good way to create a generalized JAXB container class that can be
> specialized (extended?) without losing information during marshaling?
>
> I have a Jersey Server that talks to Clients and communicates with
> specialized Jersey-based Adapters on the Client's behalf. We use JAXB on
> both the Server and the Adapters, with the Server returning Lua via a
> Provider to the Clients.
>
>
> Extending Server provided base classes in the Adapters doesn't work, the
> unmarshaler doesn't like finding "extra" elements in the base class that
> come from the extended class.
>
> Here are the code snippets, but I'm also curious about this in a general
> JAXB way.
>
> Server calls the Adapter expecting the FavoriteChannel base class:
> ClientResponse cr = restClient.get("
> http://localhost:10713/testing/favorite
> http://localhost:10713/testing/favorite ", queryParam,
> MediaType.APPLICATION_FORM_URLENCODED_TYPE);
> FavoriteChannel response = jaxbHelper.unmarshall(FavoriteChannel.class,
> cr.getEntity(String.class));
>
> Favorite base class:
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlRootElement
> public class FavoriteChannel {
> String channel;
>
> public FavoriteChannel() {}
>
> public String getChannel() {return channel;}
>
> public void setChannel(String channel) {this.channel = channel;}
> }
>
> MyFavoriteChannel extended class that is returned by the Adapter:
> @XmlAccessorType(XmlAccessType.FIELD)
> public class MyFavoriteChannel extends FavoriteChannel {
> String tuner;
>
> public MyFavoriteChannel() {}
>
> public String getTuner() {return tuner;}
>
> public void setTuner(String tuner) {this.tuner = tuner;}
> }
>
> For what it's worth all JAXB objects are available to every Server/Adapter
> and every JAXB directory contains a jaxb.index file.
>
> Is there a good generalized solution to this that doesn't loose information?
> Objects all the way down?
>
>
> --
> View this message in context:
> http://old.nabble.com/Generalized-JAXB-container-class--tp33401099p33401099.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>