users@jaxb.java.net

Marshalling and java.awt.geom.Rectangle2D

From: Pascal Quesseveur <quesseveur_at_abaksystemes.fr>
Date: Wed, 02 Jul 2014 11:49:13 +0200

Hello,

I get severe problem with Rectangle2D and JAXB: I am unable to
marshall a class containing a Rectangle2D property. I am using JAXB
shipped with Java 8 from Oracle.

Here is my code:

--8<---------------cut here---------------start------------->8---
import java.awt.geom.Rectangle2D;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Geom2D
{
    private Rectangle2D.Float rect;
    public static void main (String[] args)
    {
        try
        {
            Geom2D x = new Geom2D ();
            x.rect = new Rectangle2D.Float (0, 0, 2, 2);
            JAXBContext jc = JAXBContext.newInstance (Geom2D.class);
            Marshaller m = jc.createMarshaller();
            m.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
            m.marshal (x, System.out);
        }
        catch (Exception ex)
        {
            ex.printStackTrace (System.err);
        }
    }
}
--8<---------------cut here---------------end--------------->8---

Output:
--8<---------------cut here---------------start------------->8---
<geom2D>
    <rect>
        <frame>
            <frame>
                <frame>
...

Exception in thread "main" java.lang.StackOverflowError
...
--8<---------------cut here---------------end--------------->8---

-- 
Pascal Quesseveur
quesseveur_at_abaksystemes.fr