开发者

create nested structure using JAXB notations

开发者 https://www.devze.com 2023-02-21 21:45 出处:网络
<?xml version=\'1.0\'?> <info> <contract> <symbol>IBM</symbol> <sectype>STK</sectype>
<?xml version='1.0'?>
<info>
     <contract>
       <symbol>IBM</symbol>
       <sectype>STK</sectype>
       <exchange>SMART</exchange>
       <currency>USD</currency>
    </contract>
    <order>
      <action>SELL</action>
      <quantity>100</quantity>
      <ordertype>LMT</ordertype>
      <imtprice>imtpr开发者_运维知识库ice</imtprice>
      <transmit>false</transmit>
   </order>
</info>

I want to use jaxb annotations with existing java classes to create above XML input but i don't know how create nested xml structure based on Java classes


Try this:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {"contract", "order"})
public class Info {
@XmlElement(required = true)
private Contract contract;
@XmlElement(required = true)
private Order order; // Getters and setters
}

Another class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {"symbol", "sectype", "exchange", "currency"})
public class Contract {
@XmlElement(required = true)
private String symbol;
@XmlElement(required = true)
private String sectype;
@XmlElement(required = true)
private String exchange;
@XmlElement(required = true)
private String currency;

//Getters and setters
}

Create an order class the same way.

0

精彩评论

暂无评论...
验证码 换一张
取 消