Vikas Gunti
Vikas Gunti

Reputation: 13

JAXB umarshalling NumberFormatException Not a number: 2.444 at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:132)

While unmarhsalling I am getting the below error

java.lang.NumberFormatException Not a number: 2.444 at com.sun.xml.bind.DatatypeConverterImpl._parseInt(DatatypeConverterImpl.java:132)

Using JAXB unmarshalling method I am unmarshalling an XML which looks like below

<ProductID itemName="Pen" itemNumber="123-123" effectiveDate="2017-04-10">
  <Amount value="2.444" UOM="g"/>
</ProductID>

**in this I am trying to retrieve the value attribute in Amount tag .

While generating JAXB classes from xsd as "value" name conflicts with value xs:String so I annotated it with below code**

<xs:annotation>
    <xs:appinfo>
        <jxb:property name="valueAttribute"/>
    </xs:appinfo>
</xs:annotation> 

So in my JAXB Class ,I can see beans in the below format

@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 }
     * 
     */

Any one please help me to resolve this issue Thanks in advance....

Upvotes: 1

Views: 2313

Answers (1)

SomeDude
SomeDude

Reputation: 14228

I assume the value attribute of Amount is Byte/integer in your xsd. If it is, it should be a double or float.

Change your declaration protected Byte valueAttribute; to protected double valueAttribute or protected float valueAttribute;

and in your xsd, it should appear like:

<xs:attribute type="xs:double" name="value">
     <xs:annotation>
          <xs:appinfo>
                <jxb:property name="valueAttribute"/>
          </xs:appinfo>
     </xs:annotation>
</xs:attribute>

Upvotes: 1

Related Questions