Nathaniel Borg created AVRO-4059:
------------------------------------
Summary: [CSharp] JsonEncoder does not encode Decimal LogicalType
properly
Key: AVRO-4059
URL: https://issues.apache.org/jira/browse/AVRO-4059
Project: Apache Avro
Issue Type: Bug
Components: csharp
Reporter: Nathaniel Borg
Hey, I have started using Avro to convert GenericRecord to JSON by utilizing
the following:
{code:java}
public string ToJson(GenericRecord record, bool pretty = false)
{
var writer = new GenericDatumWriter<GenericRecord>(record.Schema);
var output = new MemoryStream();
var encoder = new JsonEncoder(record.Schema, output, pretty)
{
IncludeNamespace = false
};
writer.Write(record, encoder);
encoder.Flush();
output.Flush();
return Encoding.UTF8.GetString(output.ToArray());
}
{code}
I am noticing that for a byte type with logicalType decimal the value does not
get encoded correctly and remains in the form of bytes.
{*}For example{*}:
{*}Schema{*}:
{code:java}
{
"name": "amount",
"type": {
"type": "bytes",
"logicalType": "decimal",
"precision": 5,
"scale": 5
}
}
{code}
{*}Execution{*}:
var record = new GenericRecord(schema);
record.Add("amount", new AvroDecimal(20000.00001));
var json = ToJson(record, true);
// Returns
// {
// "amount": "w5”\u0001"
// }
// Expected
// {
// "amount: "20000.00001"
// }
--
This message was sent by Atlassian Jira
(v8.20.10#820010)