users@jaxb.java.net

Re: Marshalling and java.awt.geom.Rectangle2D

From: Iaroslav Savytskyi <iaroslav.savytskyi_at_oracle.com>
Date: Wed, 2 Jul 2014 12:54:25 +0200

Hi,

It looks like you have a cyclic dependency in Rectangle2D.Float.frame


Yarda

On 2 Jul 2014, at 11:49, Pascal Quesseveur <quesseveur_at_abaksystemes.fr> wrote:

> 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