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=“...”從標頭。
添加回答
舉報