Java – Marshall with xjc creates nested classes

<ProductInformation Context="GL">
<ProductInformation Context="GL">
 <Assets>
  <Asset ID="assetID" UserTypeID="ID">
    <Name>name</Name>
    <Reference ClassificationID="id"/>
      <Values>
        <Value AttributeID="ID">Value1</Value>
        <Value AttributeID="ID">Value2</Value>
          <MultiValue AttributeID="attributeID">
             <Value>value3a</Value>
             <Value>value3b</Value>
          </MultiValue>
     </Values>
   </Asset>
 </Assets>

 <Products>....</Products>

</ProductInformation>

I use XML - > XSD and xjc to create classes from it

Now I want to create my productinformation object and group it

My problem is xjc to create three classes and an objectfactory, as well as some nested classes in productinformation When I see the available methods, I mainly see getters instead of setters

There is no such method for the "asset" class;

asset.setValues(List<Value> values)

I finally wrote such interesting code;

ProductInformation.Assets.Asset.Values.MultiValue multivalue=new ProductInformation.Assets.Asset.Values.MultiValue();

JAXB, is this normal?

Solution

JAXB usually deals with multivalued attributes by providing a getter instead of a setter for list < whatever >, which returns a variable list - you should call getter to retrieve an initially empty list, and then create members. The objects of this list use new in the normal way and add them directly to the list You can create static nested classes in exactly the same way as top - level classes

You should use getters and setters to generate single valued properties (not lists)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>