users@jaxb.java.net

Re: Getters/Setters Missing from JAXB Generated Class

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 26 Sep 2013 08:00:55 +0200

This is the result of an XML schema that is not adequate for generating
good Java code. You'll have to construct a JAXBElement object for each
id and name value and append this to the IdAndNames list.

It would be better to change the XML schema - if you have the option.

-W

On 26/09/2013, cgswtsu78_at_gmail.com <cgswtsu78_at_gmail.com> wrote:
> I have the below JAXB generated class and I need to create this class
> and populate the data for the *id* and *name* element. Any ideas on
> how to do that with the below generated class? I don't see any
> getters/setters.
>
>
>
> **JAXB Generated Class:**
>
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "sampleType", propOrder = {
> "idAndNames"
> })
> public class SampleType
> implements ToString
> {
>
> @XmlElementRefs({
> @XmlElementRef(name = "name", type =
> JAXBElement.class),
> @XmlElementRef(name = "id", type = JAXBElement.class),
> })
> protected List<JAXBElement<?>> idAndNames;
>
> public List<JAXBElement<?>> getIdAndNames() {
> if (idAndNames == null) {
> idAndNames = new ArrayList<JAXBElement<?>>();
> }
> return this.idAndNames;
> }
>
> public String toString() {
> final ToStringStrategy strategy =
> JAXBToStringStrategy.INSTANCE;
> final StringBuilder buffer = new StringBuilder();
> append(null, buffer, strategy);
> return buffer.toString();
> }
>
> public StringBuilder append(ObjectLocator locator,
> StringBuilder buffer, ToStringStrategy strategy) {
> strategy.appendStart(locator, this, buffer);
> appendFields(locator, buffer, strategy);
> strategy.appendEnd(locator, this, buffer);
> return buffer;
> }
>
> public StringBuilder appendFields(ObjectLocator locator,
> StringBuilder buffer, ToStringStrategy strategy) {
> {
> List<JAXBElement<?>> theIdAndNames;
> theIdAndNames = (((this.idAndNames!=
> null)&&(!this.idAndNames.isEmpty()))?this.getIdAndNames():null);
> strategy.appendField(locator, this, "idAndNames",
> buffer, theIdAndNames);
> }
> return buffer;
> }
>
> }
>