2 回答
TA贡献1825条经验 获得超6个赞
试试这个,
MValuesRequest.java
@XmlRootElement(name="cs:mValuesRequest")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name ="ValuesRequest", propOrder = { "id", "transactionId", "values" })
public class MValuesRequest {
@XmlElement(name="cs:id")
protected int id;
@XmlElement(name="cs:transactionId")
protected Integer transactionId;
@XmlElement(name="cs:values")
protected Values values;
// getters and setters...
}
价值观.java
@XmlRootElement(name="cs:values")
public class Values{
@XmlElement(name="cs:timestamp")
protected String timestamp;
@XmlElement(name="cs:value")
protected List<Value> value;
// getters and setters...
}
值.java
@XmlRootElement(name="cs:value")
public class value{
@XmlAttribute(name="measurand" namespace="http://www.w3.org/XML/1998/namespace")
protected String measurand;
@XmlAttribute(name="unit" namespace="http://www.w3.org/XML/1998/namespace")
protected String unit;
@XmlValue
protected String elementValue;
// getters and setters...
}
TA贡献1808条经验 获得超4个赞
我终于可以解决这个问题,非常感谢Rathnayake。
我不必添加@XmlRootElement而只需将命名空间参数添加到@XmlAttribute。
所以目前我的 XML 参数如下所示:
@XmlAttribute(name = "context", namespace="urn://Ocpp/Cs/2012/06/")
protected ReadingContext context;
@XmlAttribute(name = "format", namespace="urn://Ocpp/Cs/2012/06/")
protected ValueFormat format;
@XmlAttribute(name = "measurand", namespace="urn://Ocpp/Cs/2012/06/")
protected Measurand measurand;
@XmlAttribute(name = "location", namespace="urn://Ocpp/Cs/2012/06/")
protected Location location;
@XmlAttribute(name = "unit", namespace="urn://Ocpp/Cs/2012/06/")
protected UnitOfMeasure unit;
请记住,这是我的 SOAP 标头:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:cs="urn://Ocpp/Cs/2012/06/" xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
我添加了命名空间=“...”值 xmlns:cs=“...”从标头。
添加回答
举报