java - 使用 avro-maven-plugin 1.9.0 生成具有十进制数据类型的类
问题描述
我有一个 Avro 架构,其中一些字段定义为十进制逻辑类型。从该架构中,我使用 avro-maven-plugin(使用 1.9.0 版)生成类。我想避免生成 ByteBuffer 类型并改用 BigDecimal。
我在较早的问题(如这里)中发现使用 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;
.
解决方案
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
<goal>idl-protocol</goal>
</goals>
<configuration>
<enableDecimalLogicalType>true</enableDecimalLogicalType>
</configuration>
</execution>
</executions>
推荐阅读
- c - 使用make时没有这样的文件或目录错误
- java - Netbeans 安装时卡住了
- python - 在 Dataframe 中查找最大容量和高于该容量的数据计数
- haskell - Haskell 检查 sum 数据类型的两个变量(而不是相应的值)是否相同
- assembly - MARS MIPS Simulator ASCII 字符串没有以 little-endian 正确存储在内存中?
- python - 在循环内运行 cumsum total
- ios - 'GADInvalidInitializationException',原因:'Google 移动广告 SDK 在没有 AppMeasurement 的情况下进行了初始化
- javascript - 打字稿:检查变量是否为空与检查变量是否有值有什么区别?
- python - 抓取特定字段
- github - 如何使用 GitHub API 按星号、观察者、提交排序 GitHub 分叉?