Announcement Announcement Module
No announcement yet.
Can't generate SPRING setters for array or collection classes with JAXB Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't generate SPRING setters for array or collection classes with JAXB

    I am trying to use JAXB to generate the required setters for Spring beans. Although according to the book Java & XML Data Binding
    by Brett McLaughlin it was possible with DTD's using

    <?xml version="1.0"?>
    <xml-java-binding-schema version="1.0-ea">
    <options package="javajaxb.generated.movies"
    default-reference-collection-type="array" />
    <element name="movies" type="class" root="true"/>

    to generate an array as in

    public Movie[] getMovie( ) {
    // implementation
    public void setMovie(Movie[] _Movie) {

    it doesn't look like that capability exists with JAXB 2.0 and XML Schemas. In their wisdom they just generate getters on Lists and tell you:

    * This accessor method returns a reference to the live list,
    * not a snapshot. Therefore any modification you make to the
    * returned list will be present inside the JAXB object.
    * This is why there is not a <CODE>set</CODE> method for the filingForm property.
    * <p>
    * For example, to add a new item, do as follows:
    * <pre>
    * getFilingForm().add(newItem);
    * </pre>

    Of course this doesn't work for Spring injection where setters are needed.

    Does anyone know different or is there a way of getting around this ?

    I've tried constructor injection in Spring but it's not as convenient and involves extensive coding of generated code (not nice).