java - JAXB 编码 NumberFormatException 不是数字 : 2. 44​​4 at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:132)

标签 java xml xsd jaxb

在解码时,我收到以下错误

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 中 Amountvalue 属性是 Byte/integer。如果是,它应该是 doublefloat

将声明 protected Byte valueAttribute; 更改为 protected double valueAttributeprotected 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. 44​​4 at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:132),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44323133/

相关文章:

java - 使用 Jaxb 解码嵌套 Map

java - Maven java.lang.ClassNotFoundException : com. mysql.jdbc.Driver

xml - 错误 : The namespace of element schema must be from schema namespace http://www. w3.org/2001/XMLSchema

java - 了解java中的垃圾收集器

java - Eclipse 插件 : menu button greyed out

java - xsd 未在某些系统上验证 : "Cannot resolve the name to a(n) ' type definition' component.“

c# - 在 C# 中以编程方式从数据库创建 XSD

python - 解析 xs :duration datatype into a Python datetime. timedelta 对象?

java - 如何从决策树模型中提取每个叶子的规则?

java - 对象引用 - 什么需要更多空间?