JAXB Bean Generation

I am using JAXB to generate beans from XSD using the JAXB plugin in Maven. This works great, expect the code to contain isSetXXXXXX () methods for each field.

eg.

for the firstName field, it creates 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 problems, and I don't want JAXB to generate them.

Is there any way to stop this behavior?

Thanks.

UPDATE

Solved: the 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 that answered my previous question .

+7
source share
1 answer

By default, the JAXB implementation (JSR-222) will not generate isSet methods. Since you get them, one of the following should be true:

  • You can specify a schema annotation that indicates: <jaxb:globalBindings generateIsSetMethod="true"/>
  • You have an external binding file that points to: <jaxb:globalBindings generateIsSetMethod="true"/>
  • You specify a Maven plug-in property to generate isSet methods.
+8
source

All Articles