简体   繁体   中英

How to map XML to POJO

I have the following result:

<Result xmlns="urn:buscape" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" totalResultsAvailable="1" totalResultsReturned="1" totalPages="1" page="1" totalLooseOffers="0" xsi:schemaLocation="http://developer.buscape.com/admin/lomadee.xsd">
  <details>
    <applicationID>999999999999999</applicationID>
    <applicationVersion>1.0</applicationVersion>
    <applicationPath/>
    <date>2016-09-12T23:50:19.722-03:00</date>
    <elapsedTime>19</elapsedTime>
    <status>success</status>
    <code>0</code>
    <message>success</message>
  </details>
  <lomadeeLinks>
    <lomadeeLink>
      <id>1</id>
      <originalLink>link</originalLink>
      <redirectLink>link2</redirectLink>
      <code>0</code>
      </lomadeeLink>
  </lomadeeLinks>
</Result>

Looking at "2.7.4 Retrieving XML data via HTTP GET" , I have to map this XML to POJO-like object in Java, here is the question, I can't find the @Root and @Element annotation and I'm not sure how to correctly map the XML into a Java object.

If you are using spring/springboot then simply you can use (YourPOJO)getWebServiceTemplate().marshalSendAndReceive(yourSOAPService);

POJO :-

@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "getOrdersResponse" }) @XmlRootElement(name = "nameOfTag", namespace = " http://example.org/yourResource ") public class GetOrdersByDateResult {

@XmlElement(name = "GetOrdersResponse")
protected GetOrdersResponseType getOrdersResponse;

getter();
setter();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM