diff --git a/lib/mongoid-avro.rb b/lib/mongoid-avro.rb index 2587859..5bc1af9 100644 --- a/lib/mongoid-avro.rb +++ b/lib/mongoid-avro.rb @@ -114,7 +114,12 @@ def convert_to_fields(klass, optional:) def convert_to_avro_format(type: , optional: true) case type.to_s - when "String", "Symbol", "BSON::Decimal128" then "string" + when "String", "Symbol" then "string" + when "BSON::Decimal128" + { + "type": "string", + "logicalType": "decimal" + } when "Integer" then "int" when "Float" then "double" when "BigDecimal" then "decimal" diff --git a/spec/mongoid_avro_spec.rb b/spec/mongoid_avro_spec.rb index b0f8b35..8e025d3 100644 --- a/spec/mongoid_avro_spec.rb +++ b/spec/mongoid_avro_spec.rb @@ -65,7 +65,12 @@ def get_field_by_name(fields, name) let(:field_name) { "decimal128" } it "convert decimal 128 to string" do - expect(field["type"]).to eq("string") + expect(field["type"]).to eq( + { + "type" => "string", + "logicalType" => "decimal" + } + ) end end