I'm kind of new to when it comes to JAXB and marhsalling / unmarshalling, and I'm struggling to do my job to get things working.
So far I have written my XSD and generated my POJOs using xjc. All of this works great. Also, when I need to turn off data that comes in as String data or a w3c document, I use JAXBContext.generateSchema () to create the appropriate schema for the expected class that I get. All of this works great.
My problem arises when I analyze the circuit generated by generateSchema (). According to JAXB docs , BigDecimal is generated as decimal type xsd.
My input sometimes contains scientific notation (ex: 1.12E12). When I try to untie this using the JAXB generated circuit, I get a javax.xml.bind.UnmarshalException exception:
[org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '1.32400146520976E-4' is not a valid value for 'decimal'.]
Is there a way to correctly parse scientific notation when using the "decimal" type or should it be "double"?
Initially, I thought that I could use double representation, since double can analyze scientific notation, however, I am dealing with financial values (this is for bank calculations), and therefore, I realized that using double representation will cause rounding errors due to it inherent limitations.
So, I think the question is how to create custom bindings that allow me to analyze scientific notation and store data in BigDecimal? I looked at XMLAdpater , but I don't understand how to use it for the case I'm looking at. If anyone can give a presentation or an example (other than the ubiquitous map example that I continue to search on the Internet), I would greatly appreciate it.
Thanks!
Eric
source share