I'm creating a web service in Java that will be consumed by an external application, probably written in C#. In my Purchase bean, I have a Currency object for the total cost. However, this leads to the following error:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.util.Currency does not have a no-arg default constructor.
I found a solution to create a custom XML Adapter to handle the Currency marshalling/unmarshalling:
public class CurrencyAdapter extends XmlAdapter<String,Currency> {
public Currency unmarshal(String val) throws Exception {
return Currency.getInstance(val);
}
public String marshal(Currency val) throws Exception {
return val.toString();
}
}
Could I use that custom XML Adapter, or use a BigDecimal (or other type) object to represent the cost?