我有一个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;
。
答案 0 :(得分:0)
<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>
答案 1 :(得分:0)
尝试将架构更改为:
{
"name": "TUR_ID",
"default": null,
"type": ["null", {
"type": "bytes",
"logicalType": "decimal",
"precision": 16,
"scale": 0
}]
}