7

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.

Community
  • 1
  • 1
adi
  • 1,711
  • 3
  • 29
  • 50
  • Hey adi, your updated XML snippet isn't valid XML, is the > after `generateIsSetMethod="true"` meant to be there? – Tom Saleeba Jan 23 '15 at 04:10

1 Answers1

9

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.
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Though I answered my question before you answered, but still this is correct and informative answer, so a big yes. – adi Oct 12 '12 at 14:19