简体   繁体   English

如何在Avro中序列化java.math.BigDecimal?

[英]How to serialize java.math.BigDecimal in Avro?

Avro schemas are defined using JSON. Avro架构使用JSON定义。 Schemas are composed of primitive types (null, boolean, int, long, float, double, bytes, and string) and complex types (record, enum, array, map, union, and fixed). 模式由基本类型(null,boolean,int,long,float,double,bytes和string)和复杂类型(记录,枚举,数组,映射,联合和固定)组成。 I want to ask which one is proper for BigDecimal. 我想问一下哪一个适合BigDecimal。

Avro introduced logical types in 1.7.7 (I believe) that should help you serialize decimal. Avro在1.7.7(我相信)中引入了逻辑类型,可以帮助您序列化小数。

https://avro.apache.org/docs/1.8.1/spec.html#Decimal https://avro.apache.org/docs/1.8.1/spec.html#Decimal

Here is the code : 这是代码:

"type": [ {
    "type": "string",
    "java-class": "java.math.BigDecimal"
 } ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM