S
Stanimir Stamenkov
[Followup-To: comp.lang.java.programmer, but change it if you find
more appropriate group.]
I'm new to using JAXB and I'm wondering whether I could make the
following bean:
@XmlRootElement(name="doc")
public class MyBean {
public String foo;
public String bar;
public String baz;
public String taz;
}
serialize as (and deserialize from):
<doc>
<head>
<foo>...</foo>
<bar>...</bar>
</head>
<body>
<foo>...</foo>
<bar>...</bar>
</body>
</doc>
i.e. how could I annotate the bean class to achieve it?
I've seen there's an @XmlElementWrapper annotation but it is used
only with collection type properties. Here's the sample code I'm
trying with:
JAXBContext jaxbContext = JAXBContext.newInstance(MyBean.class);
Marshaller marshaller = jaxbContext.createMarshaller();
MyBean data = new MyBean();
data.foo = "...";
data.bar = "...";
data.baz = "...";
data.taz = "...";
marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
marshaller.setProperty("jaxb.fragment", Boolean.TRUE);
marshaller.marshal(data, System.out);
more appropriate group.]
I'm new to using JAXB and I'm wondering whether I could make the
following bean:
@XmlRootElement(name="doc")
public class MyBean {
public String foo;
public String bar;
public String baz;
public String taz;
}
serialize as (and deserialize from):
<doc>
<head>
<foo>...</foo>
<bar>...</bar>
</head>
<body>
<foo>...</foo>
<bar>...</bar>
</body>
</doc>
i.e. how could I annotate the bean class to achieve it?
I've seen there's an @XmlElementWrapper annotation but it is used
only with collection type properties. Here's the sample code I'm
trying with:
JAXBContext jaxbContext = JAXBContext.newInstance(MyBean.class);
Marshaller marshaller = jaxbContext.createMarshaller();
MyBean data = new MyBean();
data.foo = "...";
data.bar = "...";
data.baz = "...";
data.taz = "...";
marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
marshaller.setProperty("jaxb.fragment", Boolean.TRUE);
marshaller.marshal(data, System.out);