This discussion is archived
0 Replies Latest reply: Apr 4, 2012 8:25 AM by dcminter RSS

JAXB generated collection ickyness

dcminter Newbie
Currently Being Moderated
Is there a way when generating JAXB beans from an XSD to direct it to use java.util collections of beans directly instead of creating custom container classes? There are various JAXB XSD extensions that can dictate some differences to the generated beans and there are some JAXB plugins too but I can't see anything that does this.

More details:

If I take a nice class looking something like the following:
class Foo {
   List<Bar> getBars() ...
}

class Bar {
}

// Usage: List<Bar> bars = foo.getBars();
Generate an XSD from it and then generate JAXB beans from that XSD I'll end up with something pretty much like:
class Foo {
   // Ew!
   Bars getBars() ...
}

class Bars {
   // Yuk!
   List<Bar> getBar() ...
}

class Bar {
}

// Usage: List<Bar> bars = foo.getBars().getBar();
Pretty nasty. That Bars class obviously gets generated as a place in which to stash the properties that might be in the <bars> element of the XML (which will look something like:
<foo>
  <bars> <!-- This element might have properties -->
    <bar>...<bar>
    <bar>...<bar>
    <bar>...<bar>
  </bars>
</foo>
Now in the real world scenario I'm actually starting from an XSD but the problem is the same - I want to generate beans from it, I know that the container element won't have any properties and so I want the container to be a plain old list.

Obivously I could make some of the problems go away by starting from annotated Java source files and generating the XSD but that would create its own can of snakes that I'm not going to pry into.

Any ideas?

Edited by: dcminter on Apr 4, 2012 4:25 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points