1
如何在我的Apple
類中生成BigDecimal
?現在我只有一個ByteBuffer
....Avro 1.8.2 BigDecimal(邏輯類型)的Java代碼生成
使用的Avro架構(AVSC):
{"namespace": "com.example",
"type": "record",
"name": "Apple",
"fields": [
{"name": "price", "type": {
"type": "bytes",
"logicalType": "decimal",
"precision": 9,
"scale": 2
}}
]
}
使用IDL:
@namespace("com.example")
protocol AppleProtocol {
record Apple {
@java-class("java.math.BigDecimal") decimal(9,2) price;
}
}
使用maven的生成方法mvn clean compile
,下面maven snippet:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
<goal>idl-protocol</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
這兩樣東西都會返回這個醜陋的m ethod這顯然是勉強可用...
public void setPrice(java.nio.ByteBuffer value) {
this.price = value;
}
我怎樣才能得到這種方法要求一個BigDecimal
? 這是使用阿夫羅1.8.2
謝謝!爲什麼這不是默認行爲? – Stephane