Avro-Schema-Generator
Avro-Schema-Generator copied to clipboard
Unable to handle defined type 'java.math.BigDecimal'
I have an attribute of type xs:decimal in my XSD.
Get the following error
Unable to handle defined type 'java.math.BigDecimal'.
... and suspect it's due to Avro not supporting Decimal until recently
https://issues.apache.org/jira/browse/AVRO-1402
Some 'special' xml types like dates and big numbers are handled specially. There is room to add a test and support for java.math.BigDecimal
. The real question is what the mapping should be. You can see that for BigInteger
, an Avro string is used: https://github.com/nokia/Avro-Schema-Generator/blob/master/SchemaCompiler/schemagen-core/src/main/java/com/nokia/util/avro/schemagen/SchemagenHelper.java#L271
I don't know enough to decide. There's a lengthy discussion in the Avro JIRA above about the merits of string etc.
Right. I think for now you would have to use a string and then in your application parse it into a BigDecimal object after you deserialize from Avro. For this tool at least, it would be pretty easy to add the mapping to make it a string.
See this bit about parsing strings back into BigDecimals in Java: http://stackoverflow.com/a/18231864/4966696
Okay, it seemed it was easy enough to get this tool to handle BigDecimal - added following where you pointed, compiled and installed, and then generate parsed my schema okay and generated classes
if (clazz.isAssignableFrom(clazz.owner().ref(BigDecimal.class))) { return AvroPrimitive.PrimitiveType.STRING.newInstance(); }