You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Kalle Niemitalo (Jira)" <ji...@apache.org> on 2022/06/27 06:44:00 UTC

[jira] [Commented] (AVRO-3274) Request for C# API to implement a JSON Encoder

    [ https://issues.apache.org/jira/browse/AVRO-3274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17559013#comment-17559013 ] 

Kalle Niemitalo commented on AVRO-3274:
---------------------------------------

I have been trying to implement an Avro JSON encoder in a proprietary application, as a C# class that implements the Avro.IO.Encoder interface. A difficulty in this is that Encoder.WriteNull is called by Resolver.EncodeDefaultValue but not by GenericWriter.WriteNull, so the JSON {{null}} for Schema.Type.Null has to be written in some other way. This differs from the Java org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion method.

Also, Avro.IO.Encoder does not have WriteRecordStart and WriteRecordEnd methods. This means methods like WriteInt have to detect where records start or end, and write the JSON {{&#123;}} and {{&#125;}} delimiters when needed. If empty record schemas (that do not have any fields) are to be supported, then that becomes more difficult, as a single WriteInt(42) call may have to write something like {{"field": 42, "almost_empty": &#123;"inner_empty":&#123;&#125;&#125;, "empty": &#123;&#125;&#125;&#125;}}. It is implementable, but I think it would be easier to implement something that avoids the Avro.IO.Encoder interface and instead reads from an Avro.IO.Decoder and writes JSON from that.

> Request for C# API to implement a JSON Encoder
> ----------------------------------------------
>
>                 Key: AVRO-3274
>                 URL: https://issues.apache.org/jira/browse/AVRO-3274
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: csharp
>    Affects Versions: 1.10.2
>            Reporter: Andrew Benedek
>            Priority: Major
>
> This is a request or improvement.
> I have a .NET Core application that needs to publish AVRO JSON encoded messages to our Confluent Kafka REST API.  I can see that the Java and C++ API's have a JSON encoder, but I couldn't tell from the documentation whether the C# API has it, or at least it doesn't seem to.  The documentation for the C# API is a little light on for details.  The Kafka REST API supports JSON, and AVRO JSON, but not binary AVRO from what I understand.
> The main problem facing the plain JSON we are currently publishing is that when using an AVRO schema and the union type, we hit the problem described here https://issues.apache.org/jira/browse/AVRO-2899.  We need to generate the type information in the JSON in order to satisfy the validation in the Kafka REST API.  Hence, the need for an AVRO JSON encoder.
> I can't re-write the .NET application, so I'm faced with the prospect of using either the Java or C++ API's with some sort of wrappers or interoperability framework, which I'm desperately trying to avoid.
> Any assistance or suggestions would be much appreciated.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)