我有一个 Avro 架构,其中一些字段定义为十进制逻辑类型。从该模式中,我使用 avro-maven-plugin (使用版本 1.9.0)生成类。我想避免生成 ByteBuffer 类型并使用 BigDecimal 代替。
我在较旧的问题(如 here )中发现使用版本 1.8.2。我尝试过,然后升级到 1.9.0,但仍然无法获得正确的数据类型。
架构:
{
"name": "TUR_ID",
"type": [
"null",
"bytes"
],
"default": null,
"logicalType": "decimal",
"precision": 16,
"scale": 0
}
pom.xml 中的插件配置:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<id>schemas</id>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
<goal>protocol</goal>
<goal>idl-protocol</goal>
</goals>
<configuration>
<stringType>String</stringType>
<enableDecimalLogicalType>true</enableDecimalLogicalType>
<sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
实际输出为@Deprecated public java.nio.ByteBuffer TUR_ID;
我想得到 @Deprecated public java.math.BigDecimal TUR_ID;
.
最佳答案
尝试将您的架构更改为:
{
"name": "TUR_ID",
"default": null,
"type": ["null", {
"type": "bytes",
"logicalType": "decimal",
"precision": 16,
"scale": 0
}]
}
关于java - 使用 avro-maven-plugin 1.9.0 生成具有十进制数据类型的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56444213/