66import java .nio .ByteBuffer ;
77import java .util .ArrayList ;
88
9+ import org .apache .avro .Conversions .DecimalConversion ;
910import org .apache .avro .Schema ;
1011import org .apache .avro .Schema .Type ;
1112import org .apache .avro .generic .GenericData ;
@@ -27,6 +28,8 @@ public class NonBSGenericDatumWriter<D>
2728 private final static Class <?> CLS_BIG_DECIMAL = BigDecimal .class ;
2829 private final static Class <?> CLS_BIG_INTEGER = BigInteger .class ;
2930
31+ private final static DecimalConversion BIG_DECIMAL_CONVERSION = new DecimalConversion ();
32+
3033 public NonBSGenericDatumWriter (Schema root ) {
3134 super (root );
3235 }
@@ -97,6 +100,11 @@ protected void write(Schema schema, Object datum, Encoder out) throws IOExceptio
97100 super .writeWithoutConversion (schema , ByteBuffer .wrap ((byte []) datum ), out );
98101 return ;
99102 }
103+ if (datum .getClass () == CLS_BIG_DECIMAL ) {
104+ super .writeWithoutConversion (schema , BIG_DECIMAL_CONVERSION .toBytes (
105+ (BigDecimal ) datum , schema , schema .getLogicalType ()), out );
106+ return ;
107+ }
100108 break ;
101109 case FIXED :
102110 // One more mismatch to fix
@@ -111,6 +119,11 @@ protected void write(Schema schema, Object datum, Encoder out) throws IOExceptio
111119 super .writeWithoutConversion (schema , new GenericData .Fixed (schema , (byte []) datum ), out );
112120 return ;
113121 }
122+ if (datum .getClass () == CLS_BIG_DECIMAL ) {
123+ super .writeWithoutConversion (schema , BIG_DECIMAL_CONVERSION .toFixed (
124+ (BigDecimal ) datum , schema , schema .getLogicalType ()), out );
125+ return ;
126+ }
114127 break ;
115128
116129 default :
0 commit comments