虽然unmarhsalling我收到以下错误
java.lang.NumberFormatException 不是数字:2.444 at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:132)
使用JAXB解组方法我正在解组XML,如下所示
<ProductID itemName="Pen" itemNumber="123-123" effectiveDate="2017-04-10">
<Amount value="2.444" UOM="g"/>
</ProductID>
**在这里我试图检索Amount标签中的value属性。
从xsd生成JAXB类作为&#34; value&#34; name与值xs:String冲突,所以我用下面的代码**
注释它<xs:annotation>
<xs:appinfo>
<jxb:property name="valueAttribute"/>
</xs:appinfo>
</xs:annotation>
所以在我的JAXB类中,我可以看到以下格式的bean
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "value" })
public static class Amount {
@XmlValue
protected String value;
@XmlAttribute(name = "value")
protected Byte valueAttribute;
@XmlAttribute(name = "UOM")
protected String uom;
/**
* Gets the value of the value property.
*
* @return possible object is {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the valueAttribute property.
*
* @return possible object is {@link Byte }
*
*/
public Byte getValueAttribute() {
return valueAttribute;
}
/**
* Sets the value of the valueAttribute property.
*
* @param value
* allowed object is {@link Byte }
*
*/
public void setValueAttribute(Byte value) {
System.out.println("insde set value attribute"+value.byteValue());
this.valueAttribute = value;
}
/**
* Gets the value of the uom property.
*
* @return possible object is {@link String }
*
*/
任何人请帮我解决这个问题 提前谢谢....
答案 0 :(得分:1)
我认为您的xsd中value
的{{1}}属性为Amount
/ Byte
。如果是,则应为integer
或double
。
将您的声明float
更改为protected Byte valueAttribute;
或protected double valueAttribute
;
在xsd中,它应该显示为:
protected float valueAttribute