Using BigDecimal in JAXB marshalling

Create adaptor

puclic class BigDecimalAdaptor implements XmlAdapter<String, BigDecimal>

and use for (XmlAccessType.FIELD) access

@XmlJavaTypeAdapter(BigDecimalAdaptor.class)
private BigDecimal sum;   

and for (XmlAccessType.PROPERTY) access

@XmlJavaTypeAdapter(BigDecimalAdaptor.class)  
public getSum()
{
   return sum;
}

adaptor can be like

public class BigDecimalAdapter extends XmlAdapter<String, BigDecimal>{

    @Override
    public String marshal(BigDecimal value) throws Exception 
    {
        if (value!= null)
        {
            return value.toString();
        }
        return null;
    }

    @Override
    public BigDecimal unmarshal(String s) throws Exception 
    {
       return new BigDecimal(s);
    }
}

You write an XmlAdapter<String, BigDecimal> and you annotate the getter of sum with it: @XmlJavaTypeAdapter(BigDecimalStringAdapter.class).