users@jaxb.java.net

Generalized JAXB container class?

From: msummers <msummers57_at_gmail.com>
Date: Mon, 27 Feb 2012 08:54:55 -0800 (PST)

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.