users@jaxb.java.net

AW: Advice for serializing classes I cannot annotate ?

From: Ernst, Matthias <matthias.ernst_at_coremedia.com>
Date: Wed, 25 Oct 2006 14:35:55 +0200

Isn't that what an XmlAdapter is for?

Implement class "XmlPoint { public int x, y; }" that is serializable by Jaxb.
Implement PointAdapter extends XmlAdapter<XmlPoint,java.awt.Point> to convert back and forth.
Annotate Foo.location with @XmlJavaTypeAdapter(PointAdapter.class).

Matthias

> -----Ursprüngliche Nachricht-----

> //Java file:
> import java.awt.Point; // Note the 'Point' class is not
> under my control
> @XmlRootElement(name="foo")
> public class Foo {
> @XmlElement
> Point location;
> // ... other stuff ...
> }
>
> //(expected) XML file:
> <foo>
> <location x="123" y="345"/>
> ...
> </foo>
>
> I can annotate Foo (it's my source code), but I cannot
> annotate the java.awt.Point source.