users@jaxb.java.net

Mapping custom class to URI XML representation

From: Markus Karg <karg_at_quipsy.de>
Date: Wed, 2 Feb 2011 18:41:04 +0100

Hello JAXB Community,

 

I have two classes:

 

@XmlRootElement public class A {

  public B b;

}

 

@XmlRootElement public class B {

  public @XmlID @XmlAttribute int id;

}

 

If I marshal those, I want to get that:

 

<A b="http://...base_uri.../id"/>

 

I hope you understand what I mean.

 

I have seen that there is a @XmlAttachmentRef annotation which seems to
do something like that, but I cannot change the type of b to DataHandler
as required according to the JavaDocs, but it must definitively stay as
type B.

 

How can I tell JAXB that it shall replace the reference to B with an URI
and vice versa (i. e. add a given base_uri at marshalling and append it
by id / http-GET and unmarshal the URI at unmarshalling)? Is there some
special annotation I can add to @XmlAttribute to tell some kind of
"marshalling / unmarshalling customizer"?

 

Thanks!

Markus