在解码时,我收到以下错误
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 类,因为“值”名称与值 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 }
*
*/
任何人请帮我解决这个问题 提前致谢....
最佳答案
我假设您的 xsd 中 Amount
的 value
属性是 Byte
/integer
。如果是,它应该是 double
或 float
。
将声明 protected Byte valueAttribute;
更改为 protected double valueAttribute
或 protected float valueAttribute
;
在您的 xsd 中,它应该显示为:
<xs:attribute type="xs:double" name="value">
<xs:annotation>
<xs:appinfo>
<jxb:property name="valueAttribute"/>
</xs:appinfo>
</xs:annotation>
</xs:attribute>
关于java - JAXB 编码 NumberFormatException 不是数字 : 2. 444 at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:132),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44323133/