BertrandM created AVRO-4124:
-------------------------------
Summary: [java][avro-maven-plugin] LogicalType "big-decimal"
generate java.nio.ByteBuffer instead of BigDecimal
Key: AVRO-4124
URL: https://issues.apache.org/jira/browse/AVRO-4124
Project: Apache Avro
Issue Type: Bug
Components: java
Affects Versions: 1.12.0
Environment: Java
Maven
Springboot 2
Reporter: BertrandM
Attachments: Quote.avsc
Hi, i face to an issue during code generation and i did not find solution or
existing Jira ticket about this subject
*Context:*
On our projet we was on avro 1.11.0 with java. To define big-decimal, we used
Decimal logical type with scale and precision
{code:java}
LogicalTypes.decimal(BIGDECIMAL_PRECISION,
BIGDECIMAL_SCALE).addToSchema(Schema.create(Schema.Type.BYTES)); {code}
But we face some issue du to undetermined large number and we had update scale
and precision multiple time.
Avro generator correctly generate java properties as BigDecimal in avro pojo
Since 1.12.0 ([Specification | Apache
Avro)|https://avro.apache.org/docs/1.12.0/specification/#decimal] we can define
big-decimal logical type to avoid fixed scale/precision.
So to avoid schema change again, i try to use the new logical type as we are in
java ecosystem. Update dependencies add this logical type in schema builder :
{code:java}
codeLogicalTypes.bigDecimal().addToSchema(Schema.create(Schema.Type.BYTES));
{code}
*Problem :*
By using Big-decimal LogicalType, i thought that maven plugin will continue to
generate BigDecimal but now i have ByteBuffer instead.
_Maven configuration :_
{code:java}
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.12.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/schemas/avro/merged</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/src/main/java/</outputDirectory>
<enableDecimalLogicalType>true</enableDecimalLogicalType>
</configuration>
</execution>
</executions>
</plugin>
{code}
_Avro schema:_
{code:java}
{
"name" : "value",
"type" : {
"type" : "bytes",
"logicalType" : "big-decimal"
}
} {code}
_[^Quote.avsc]_
_Java CLass:_
{code:java}
private java.nio.ByteBuffer value;
{code}
I searched in github repository but did not find where is the problem or if i
miss something on configuration
Thanks for help
--
This message was sent by Atlassian Jira
(v8.20.10#820010)