The generated comment for the getter method does describe the reasons
for not also generating a setter method. It wants you to use the add()
method on the List instead.
If you really need a setter method, then a custom XJC plugin is what you
need:
https://jaxb.dev.java.net/plugin.html
Marcos wrote:
> Hi all,
>
> I' currently facing a very interesting situation .... I've the following
> .xsd (some parts were omitted for brevity).:
>
> <xs:element name="loaderJob">
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element ref="sql" minOccurs="0" maxOccurs="unbounded"/>
> <xs:element ref="definitionInclude" minOccurs="0"
> maxOccurs="unbounded"/>
> <xs:element ref="importDefinition" minOccurs="0"
> maxOccurs="unbounded"/>
> <xs:element ref="restartCounter" minOccurs="0"/>
> <xs:element ref="variables" minOccurs="0"/>
> <xs:element ref="jdbcDefaultParameters" minOccurs="0"/>
> <xs:element ref="echo" minOccurs="0" maxOccurs="unbounded"/>
> <xs:element ref="copyTable" minOccurs="0"
> maxOccurs="unbounded"/>
> </xs:choice>
> </xs:element>
>
> When I run the binding compiler against this .xsd I get access to the
> elements through a List<Object> such as.:
> (Annotations removed for brevity)
>
> public class LoaderJob implements Serializable
> {
>
> /**
> * Gets the value of the sqlOrDefinitionIncludeOrImportDefinition
> property.
> *
> * <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
> sqlOrDefinitionIncludeOrImportDefinition property.
> *
> * <p>
> * For example, to add a new item, do as follows:
> * <pre>
> * getSqlOrDefinitionIncludeOrImportDefinition().add(newItem);
> * </pre>
> *
> *
> * <p>
> * Objects of the following type(s) are allowed in the list
> * {_at_link Echo }
> * {_at_link JdbcDefaultParameters }
> * {_at_link ImportDefinition }
> * {_at_link RestartCounter }
> * {_at_link CopyTable }
> * {_at_link Sql }
> * {_at_link DefinitionInclude }
> * {_at_link Variables }
> *
> *
> */
> public List<Object> getSqlOrDefinitionIncludeOrImportDefinition() {
> if (sqlOrDefinitionIncludeOrImportDefinition == null) {
> sqlOrDefinitionIncludeOrImportDefinition = new
> ArrayList<Object>();
> }
> return this.sqlOrDefinitionIncludeOrImportDefinition;
> }
>
> }
>
> Ok this method conforms to JavaBeans standards but the property
> generated is "Read Only" and I have a routine that uses XMLEncoder to
> save all the Java Objects tree to a stream and unfortunately this
> composed property is not being correclty serialized by XMLEncoder ;-(
>
> Is there some way to generate a setter for this property ? or even is
> this the right approach to solve that ?
> Would be perfect for me to save all the hierarchy of objects using
> XMLEncoder ... because I don't need to touch in some already tested
> routines ;-)
>
> Thank you very much
> Marcos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>