@ Santosh Thank you! The XMLAdapter was what I needed. Also, as I said in my question, I generate client classes with Apache CXF. In this form, I had to add the following code to bindings.xjb (the binding file that is used for cxf-codegen-plugin in maven).
<jaxb:javaType name="java.math.BigDecimal" xmlType="xs:decimal" parseMethod="sample.BigDecimalFormater.parseBigDecimal" printMethod="sample.BigDecimalFormater.printBigDecimal" />
This is my formatting code:
public class BigDecimalFormater { public static String printBigDecimal(BigDecimal value) { value.setScale(5); return value.toPlainString(); } public static BigDecimal parseBigDecimal(String value) { return new BigDecimal(value); } }
Then this plugin generates Adapter for me
public class Adapter1 extends XmlAdapter<String, BigDecimal> { public BigDecimal unmarshal(String value) { return (sample.BigDecimalFormater.parseBigDecimal(value)); } public String marshal(BigDecimal value) { return (sample.BigDecimalFormater.printBigDecimal(value)); } }
In the generated BigDecimal class, the field has the annotation @XmlJavaTypeAdapter (Adapter1.class) and fixes the problem.
source share