users@jaxb.java.net

Re: JAXB Default Field Value

From: Hello! hello <prosp4300_at_gmail.com>
Date: Fri, 29 Apr 2011 01:53:36 +0800

Fixed value would be better mapping to constant field

Please check "fixedAttributeToConstantProperty"

2011/4/28 <jej2003_at_gmail.com>

> First sorry for the double post if this shows up twice...
>
> I have a schema with an attribute with a fixed value. JAXB generates
> the following given the schema:
>
> @XmlAttribute(name = "version")
> protected String version;
> public String getVersion() {
> if (version == null) {
> return "2.0";
> } else {
> return version;
> }
> }
>
> but since the XmlAccessType on the class is set to XmlAccessType.FIELD
> the version value is null. Is there a way when generating the class
> through an external binding to instead generate a class that looks
> like this:
>
> @XmlAttribute(name = "version")
> protected String version = "2.0";
> public String getVersion() {
> return version;
> }
>