Skip to content

Instantly share code, notes, and snippets.

@pitometsyurii

pitometsyurii/java

Last active Nov 16, 2018
Embed
What would you like to do?
XMLHelper
public class XmlHelper {
private static Logger logger = LoggerFactory.getLogger(XmlHelper.class);
public static <T> T fromXml(String xml, Class<?> clazz) {
Unmarshaller um = null;
try {
um = JAXBContext.newInstance(clazz).createUnmarshaller();
Object obj = um.unmarshal(new StringReader(xml));
return (T) obj;
} catch (JAXBException e) {
e.printStackTrace();
logger.error("Can't unmarshal from XML: ", e);
}
return null;
}
}
package com.macquarie.mpl.web.model.dte.genericxml;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "report")
public class ForwardCashReportResponse {
@XmlElement(name = "value")
public Value value;
@XmlElement(name = "type")
public Type type;
public static class Type {
@XmlElement(name = "error")
public Error error;
}
public static class Error {
@XmlElement(name = "vector")
public Vector vector;
}
public static class Vector {
@XmlElement(name = "forward_cash")
public String fwdCash;
}
public static class Value {
@XmlElement(name = "list")
public RowList list;
@XmlElement(name = "error")
public String errorMessage;
}
public static class RowList {
@XmlElement(name = "litem")
public List<Litem> list;
}
public static class Litem {
@XmlElement(name = "forward_cash")
public ForwardCash forwardCash;
}
public static class ForwardCash {
@XmlElement(name = "date")
public String date;
@XmlElement(name = "amount")
public double amount;
@XmlElement(name = "asset")
public String asset;
@XmlElement(name = "contingent")
public String contingent;
@XmlElement(name = "payment_key")
public String payment_key;
@XmlElement(name = "counterparty")
public String counterparty;
@XmlElement(name = "description")
public String description;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment