Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB Bean Generation

I am using JAXB for generating beans from XSD's using a JAXB plugin in Maven. This is working fine, expect that the code contains isSetXXXXXX() methods for each field.

e.g.

for a field firstName, it is producing the following code:

@XmlElement(name = "FirstName", required = true)
    protected String firstName;

  public String getFirstName() {
        return firstName;
    }

 public void setFirstName(String firstName) {
        this.token = firstName;
    }

    public boolean isSetFirstName() {
        return (this.firstName!= null);
    }

This isSetFirstName() method is causing issues and I don't want JAXB to generate these.

Is there a way to stop this behaviour?

Thanks.

UPDATE

Solved this: Problem was in the xjb file, generateIsSetMethod was set to true.

<xs:annotation>
   <xs:appinfo>
      <jaxb:globalBindings generateIsSetMethod="true">

      bindingStyle="modelGroupBinding"
         choiceContentProperty="true" >

           <xjc:serializable uid="12343"/>
           <jaxb:javaType name="short" 
              xmlType="xs:long" 
              printMethod="javax.xml.bind.DatatypeConverter.printShort"   
              parseMethod="javax.xml.bind.DatatypeConverter.parseShort"/>

      </jaxb:globalBindings>
   </xs:appinfo>
</xs:annotation>

And this answered my previous question as well.

like image 635
adi Avatar asked Oct 12 '12 14:10

adi


1 Answers

By default a JAXB (JSR-222) implementation will not generate isSet methods. Since you are getting them one of the following must be true:

  1. You can a schema annotation that specifies: <jaxb:globalBindings generateIsSetMethod="true"/>
  2. You have an external binding file that specifies: <jaxb:globalBindings generateIsSetMethod="true"/>
  3. You are specifying a property to the Maven plug-in to generate the isSet methods.
like image 80
bdoughan Avatar answered Sep 21 '22 17:09

bdoughan