0

My JAXB has generated java class like below:

 <pre>
 * &lt;complexType name="StubCalculationPeriodAmount">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="calculationPeriodDatesReference" type="{http://www.fpml.org/2009/FpML-4-7}CalculationPeriodDatesReference"/>
 *         &lt;choice>
 *           &lt;sequence>
 *             &lt;element name="initialStub" type="{http://www.fpml.org/2009/FpML-4-7}StubValue"/>
 *             &lt;element name="finalStub" type="{http://www.fpml.org/2009/FpML-4-7}StubValue" minOccurs="0"/>
 *           &lt;/sequence>
 *           &lt;element name="finalStub" type="{http://www.fpml.org/2009/FpML-4-7}StubValue"/>
 *         &lt;/choice>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StubCalculationPeriodAmount", propOrder = {
    "content"
})
public class StubCalculationPeriodAmount {

    @XmlElementRefs({
        @XmlElementRef(name = "calculationPeriodDatesReference", namespace = "http://www.fpml.org/2009/FpML-4-7", type = JAXBElement.class),
        @XmlElementRef(name = "finalStub", namespace = "http://www.fpml.org/2009/FpML-4-7", type = JAXBElement.class),
        @XmlElementRef(name = "initialStub", namespace = "http://www.fpml.org/2009/FpML-4-7", type = JAXBElement.class)
    })
    protected List<JAXBElement<?>> content;

    /**
     * Gets the rest of the content model. 
     * 
     * <p>
     * You are getting this "catch-all" property because of the following reason: 
     * The field name "FinalStub" is used by two different parts of a schema. See: 
     * line 14273 of file:/C:/Users/rmei/Eclipse_git_workspace/mlp-fpml/src/main/xsd/fpml-4.7/merged-schema/fpml-main-4-7.xsd
     * line 14267 of file:/C:/Users/rmei/Eclipse_git_workspace/mlp-fpml/src/main/xsd/fpml-4.7/merged-schema/fpml-main-4-7.xsd
     * <p>
     * To get rid of this property, apply a property customization to one 
     * of both of the following declarations to change their names: 
     * Gets the value of the content 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 content property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getContent().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link StubValue }{@code >}
     * {@link JAXBElement }{@code <}{@link StubValue }{@code >}
     * {@link JAXBElement }{@code <}{@link CalculationPeriodDatesReference }{@code >}
     * 
     * 
     */
    public List<JAXBElement<?>> getContent() {
        if (content == null) {
            content = new ArrayList<JAXBElement<?>>();
        }
        return this.content;
    }

This java class do not have the appropriate getter and setter method. I want the jaxb to be able to generate the java class like below:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StubCalculationPeriodAmount", propOrder = {
    "calculationPeriodDatesReference",
    "initialStub",
    "finalStub"
})
public class StubCalculationPeriodAmount {

    protected CalculationPeriodDatesReference calculationPeriodDatesReference;
    protected StubValue initialStub;
    protected StubValue finalStub;

    /**
     * Gets the value of the calculationPeriodDatesReference property.
     * 
     * @return
     *     possible object is
     *     {@link CalculationPeriodDatesReference }
     *     
     */
    public CalculationPeriodDatesReference getCalculationPeriodDatesReference() {
        return calculationPeriodDatesReference;
    }

    /**
     * Sets the value of the calculationPeriodDatesReference property.
     * 
     * @param value
     *     allowed object is
     *     {@link CalculationPeriodDatesReference }
     *     
     */
    public void setCalculationPeriodDatesReference(CalculationPeriodDatesReference value) {
        this.calculationPeriodDatesReference = value;
    }

    /**
     * Gets the value of the initialStub property.
     * 
     * @return
     *     possible object is
     *     {@link StubValue }
     *     
     */

I am not sure how should I do this. Since this java class is automatically generated.

I want to get the InitialStub value, could anyone help me with this? Thanks!

xsd schema:

</xsd:complexType>
<xsd:complexType name="StubCalculationPeriod">
<xsd:annotation>
<xsd:documentation xml:lang="en">A type describing the Stub Calculation Period.</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:annotation>
<xsd:documentation xml:lang="en">Choice group between mandatory specification of initial stub and optional specification of final stub, or mandatory final stub.</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="initialStub" type="Stub"/>
<xsd:element name="finalStub" type="Stub" minOccurs="0"/>
</xsd:sequence>
<xsd:element name="finalStub" type="Stub"/>
</xsd:choice>
</xsd:complexType>
Rachel
  • 349
  • 1
  • 3
  • 19
  • Try generating schema from that annotated class, and you'll see the schema you have to define to get the class. – Andreas Aug 13 '18 at 18:57
  • Where from comes you xsd? Do you have control over it? Can you attach full xsd, from which you class is generated? – Ondřej Fischer Aug 13 '18 at 18:58
  • @Andreas how to generate from annoted class? i am using Maven. so do i need to do a maven clean install again? that did not work... – Rachel Aug 13 '18 at 19:01
  • @OndřejFischer Hi , I attached the schema – Rachel Aug 13 '18 at 19:03
  • What happened to `calculationPeriodDatesReference` in that schema? *FYI:* Your code is showing `StubCalculationPeriodAmount`, but the schema is showing `StubCalculationPeriod`. – Andreas Aug 13 '18 at 19:08
  • @Andreas this code is copy from other similar java class generate from other fpml version schema. i just want to give an example.My probelm is that i do not know how to regenerate the java class – Rachel Aug 13 '18 at 19:32
  • 1
    The schema is too complex for a direct mapping to Java field, since there are two elements with the same name. So the code generator falls back to a list of `JAXBElement`, where it *is* possible to have two values with the same name and potentially different specification (e.g. the `minOccurs="0"` vs the implied `minOccurs="1"` difference in your case). If you want clean Java code generated, then you need to modify the schema and forego part of the validation it currently specifies, by making it simply two optional fields, i.e. no ``. – Andreas Aug 13 '18 at 20:16

0 Answers0