簡體   English   中英

JAXB的詳細編組

[英]JAXB unmarshalling in detail

我是jaxb使用的新手,我能夠封送一個帶有xml注釋到.xml的Java類,但無法在解組時檢索數據。 當我對未編組的數據執行sysout時,它將打印上下文的地址,而不是實際值。 我不確定哪里出問題了。

<collections>
    <collectionclass="testclass">
        <group>
            <header code="T123" type="toys"/>
            <obj1 location="1" shelf="4" />
            <obj2 location="7" shelf="2"  count="3"/>
                <associations>
                    <association type="String" associatedName="train" associatedFieldSize="0"/>
                    <association type="DataLength" associatedName="ship" associatedFieldSize="0"/>
                </associations>
            </obj2>
         </group>
           <collectionclass="testclass">
  </collections>

另外,我還想了解有關在解組xml文檔時生成的“ jaxb上下文”和“ java模型/ java模型類”之類的術語的詳細信息,以及它是如何變成圖片的。

提前致謝!

嘗試如下。

嘗試{

    File file = new File("C:\\file.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    Customer customer = (Customer) jaxbUnmarshaller.unmarshal(file);
    System.out.println(customer);

  } catch (JAXBException e) {
    e.printStackTrace();
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM