Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > JAXB: Wrap prop...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 1358 of 1403
Post > Topic >>

JAXB: Wrap property gourps

by Stanimir Stamenkov <s7an10@[EMAIL PROTECTED] > Jun 17, 2008 at 06:47 PM

[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:

@[EMAIL PROTECTED]
(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 @[EMAIL PROTECTED]
 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);

-- 
Stanimir
 




 1 Posts in Topic:
JAXB: Wrap property gourps
Stanimir Stamenkov <s7  2008-06-17 18:47:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Dec 4 0:44:27 CST 2008.