Skip to main content

JAXB 2.0 doesn't generate setters for LISTs or arrays that I need for Spring

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
javaprogrammer
Offline
Joined: 2004-05-25

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 poosible 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"/>
</xml-java-binding-schema>
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:
<p>
* 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).

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
javaprogrammer
Offline
Joined: 2004-05-25

Oh I found it on this post
http://cxf.547215.n5.nabble.com/NPE-in-generated-setter-method-when-coll...
collectionType="indexed" in the globalBindings-tag
it works in schema internal global bindings as well

<jaxb:globalBindings collectionType="indexed" >