views:

147

answers:

2

Hi all I am struggling with a simple JAXB customization issue. I have an schema like this. (its actually a snippet of Bing Maps Web Services schema)

 <xs:complexType name="GeocodeOptions">
  <xs:sequence>
    <xs:element minOccurs="0" name="Count" nillable="true" type="xs:int" />
    <xs:element minOccurs="0" name="Filters" nillable="true" type="ArrayOfFilterBase" />
  </xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfFilterBase">
  <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="unbounded" name="FilterBase" nillable="true" type="FilterBase" />
  </xs:sequence>
</xs:complexType>

Now when I generate java classes using wsimport, it creates code structure like:

public class GeocodeOptions implements Serializable {
...
    public ArrayOfFilterBase getFilters() {
    ...
    }

    public void setFilters(ArrayOfFilterBase value) {
    ...
    }
}

public class ArrayOfFilterBase implements Serializable {
...
    public List<FilterBase> getFilterBaseList() {
    ...
    }
}

As you notice ArrayOfFilterBase is a container class which I would like to omit. I would like to have the getFilterBaseList() method directly inside GeocodeOptions class.

Is it possible to do it through JAXB customization? I searched hard for it but could not find a solution.

Thanks for your help.

Regards Nabeel Mukhtar

+1  A: 

The quick answer, is no.

You would need to move the FilterBaseList element to GeocodeOptions.

Is there any particular problem you are trying to resolve with this approach?

Generic Prodigy
Thanks for your help.Actually with these container classes the API is getting bloated unnecessarily. I would like to have a simpler interface for the generated code. Can't modify the schema/wsdl either. Any other alternative?
nabeelmukhtar
You could use an inner class, but that will essentially use almost the same number of lines, although you won't need separate Java class source files.
Generic Prodigy
+1  A: 

Yes, you can omit the container using the @XmlElementWrapper annotation. Your code should look something like this:

public class GeocodeOptions implements Serializable {
       @XmlElementWrapper(name = "...")
       @XmlElement(name = "...")
      public List<FilterBase> getFilterBaseList() {
       ...
      }
}
B. Todorov