2012-03-28 97 views
0

如何用JAXB注释(XMLJavaTYpeAdapter)描述Java类?其实我想将以下XML格式解组成Java对象。JAXB解组XmlJavaTypeAdapter

<map> 
    <entry key="extraProperties"> 
     <map> 
      <entry key="message" value=""/> 
      <entry key="entity"> 
       <map> 
        <entry key="starttime" value="1330086091375"/> 
        <entry key="state" value="1"/> 
        <entry key="uptime" value="2837656746"/> 
       </map> 
      </entry> 
      <entry key="childResources"> 
       <map> 
        <entry key="transaction-service" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/transaction-service"/> 
        <entry key="http-service" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/http-service"/> 
        <entry key="applications" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/applications"/> 
        <entry key="deployment" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/deployment"/> 
        <entry key="jvm" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/jvm"/> 
        <entry key="web" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/web"/> 
        <entry key="security" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/security"/> 
        <entry key="network" value="https://47.168.96.31:4848/monitoring/domain1/instanceMaster/network"/> 
       </map> 
      </entry> 
     </map> 
    </entry> 
    <entry key="message" value=""/> 
    <entry key="exit_code" value="SUCCESS"/> 
    <entry key="command" value="Monitoring Data"/> 
</map> 

回答

0

我已经定义了两个类名Map和Entry,它将Map元素保存为List和两个附加属性。现在好了,因为这个xml结构是静态的,所以很容易创建对应于XML的类。我想知道下面的XML结构如何被映射到java classess中。 正如你所看到的,一些入口标签有list元素,一些入口标签onty有地图元素,它基于rntry的关键字名称。

<map> 
    <entry key="extraProperties"> 
     <map> 
      <entry key="methods"> 
       <list> 
        <map></map> 
        <map></map> 
       </list> 
      </entry> 
      <entry key="instanceList"> 
       <list> 
        <map></map> 
        <map></map> 
       </list> 
      </entry> 
     </map> 
    </entry> 
    <entry key="message" value="instanceMaster running 
instanceRemote running "/> 
    <entry key="exit_code" value="SUCCESS"/> 
    <entry key="command" value="list-instances AdminCommand"/> 
</map> 
+0

向Map类中添加额外的一个XmlElement解决了我的问题。 – 2012-03-29 12:30:53