users@jaxb.java.net

RE: JAXB 2.0 default values

From: Scott Allan <sallan1000_at_aol.com>
Date: Tue, 6 Sep 2005 11:23:07 -0500

Wouldn't it also make sense to assign the default value to the
corresponding bean? I may not always be unmarshaling the bean to use
it.



    protected String test="testvalue";





> -----Original Message-----

> From: Ed Mooney [mailto:Ed.Mooney_at_Sun.COM]

> Sent: Tuesday, September 06, 2005 7:50 AM

> To: users_at_jaxb.dev.java.net

> Subject: Re: JAXB 2.0 default values

>

>

> The default gets assigned when you unmarshal an element with no value:

>

> xjc.sh test.xsd;javac `find . -name '*.java'`;java test

> parsing a schema...

> compiling a schema...

> testvalue

>

> -- Ed

>

> Scott Allan wrote:

> > Does JAXB 2.0 support the element default attribute?

> > for example:

> > <xs:element name="test" type="xs:string" default="testvalue"/>

> >

> > This compiles as such:

> > @XmlElement(defaultValue = "testvalue")

> > protected String test;

> >

> > but when I try to read the value, it is null:

> >

> > MyObject myObject = objFactory.createMyObject();

> > System.out.println(myObject.isSetTest());

> > System.out.println(myObject.getTest());

> >

> > false

> > null

> >

> [ ... ]

>




  _____

<< ella for Spam Control >> has removed 26707 Spam messages and set
aside 2 Newsletters for me
You can use it too - and it's FREE! www.ellaforspam.com