1

I have 2 complex types in a XSD file that I may not change. One has multiple children "filepath" occurrences and the other always has 1 "filepath" child.

JAXB generates either of these differently, one is put in a list of entities and the other is just the single JAXB entity. This is a problem for me, as I want JAXB to give me 2 equal classes for the sake of inheritance. (I am using JAXB inheritance plugin)

Is there a way to make JAXB generate the filepaths child property of the "EntitySingleFile" complextype as a list, perhaps using JAXB bindings?

These are the XSD definitions:

<xs:element name="EntitySingleFile">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="filePaths" type="bgl:FilePaths" minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

and

<xs:element name="EntityMultiFile">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="filePaths" type="bgl:FilePaths" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

This is what im currently getting from these XSD files:

@XmlRootElement(name = "EntitySingleFile")
public class EntitySingleFile
    implements IDrawConfiguration
{
    @XmlElement(required = true, type = FilePaths.class)
    protected IFilePaths filePaths;
....

And for multifile:

@XmlRootElement(name = "EntityMultiFile")
public class EntityMultiFile
    implements IDrawConfiguration
{
    @XmlElement(required = true, type = FilePaths.class)
    protected List<IFilePaths> filePaths;
lexicore
  • 42,748
  • 17
  • 132
  • 221
RoyB
  • 3,104
  • 1
  • 16
  • 37
  • I've removed the tag:maven-jaxb2-plugin tag since this has nothing to do with th `maven-jaxb2-plugin`. – lexicore Dec 31 '14 at 22:38

1 Answers1

1

Since you probably just need the collection method in order to implement a certain interface, I think the easiest would be to use something like the Code Injector plugin to generate an additional getFilePaths() method.

See these answers for the hinst on usage:

You'll probably also need jaxb:property customization to avoid naming collisions in getters, but I hope you see how it's solveable.

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221