You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Martin Mucha <al...@gmail.com> on 2019/04/13 13:24:03 UTC
is it possible to deserialize JSON with optional field?
Hi,
is it possible by design to deserialize JSON with schema having optional
value?
Schema:
{
"type" : "record",
"name" : "UserSessionEvent",
"namespace" : "events",
"fields" : [ {
"name" : "username",
"type" : "string"
}, {
"name" : "errorData",
"type" : [ "null", "string" ],
"default" : null
}]}
Value to deserialize:
{"username" : "2271AE67-34DE-4B43-8839-07216C5D10E1"}
I also tried to change order of type, but that changed nothing. I know I
can produce ill-formated JSON which could be deserialized, but that's not
acceptable. AFAIK given JSON with required `username` and optional
`errorData` cannot be deserialized by design. Am I right?
thanks.
Re: is it possible to deserialize JSON with optional field?
Posted by Zoltan Farkas <zo...@yahoo.com>.
Please don’t insinuate any “promotion” efforts from my side.
I am simply trying to help, and insinuations like this can only hinder participation and not help the project in any way.
You don’t have to use my fork, just lift the code out into your project or your fork. (Just look at it as a “gist”).
If you want to have this to be part of the avro library, you can contribute a PR.
There is a JIRA for this already: https://issues.apache.org/jira/browse/AVRO-1582 <https://issues.apache.org/jira/browse/AVRO-1582>
I can speak from experience that the community is welcoming to contributors/contributions.
—Z
> On Apr 16, 2019, at 5:54 AM, Martin Mucha <al...@gmail.com> wrote:
>
> Hi, thanks for responding.
>
> I know that you promote your fork, however considering I might not be able to move away from "official release", is there an easy way how to consume this? Since I cannot see it ...
>
> Maybe side question: official avro seems to be dead. There are some commits made, but last release happened 2 years ago, fatal flaws are not being addressed, almost 10 years old valid bug reports are just ignored, ... Does anyone know about any sign/confirmation that avro community will be moving toward something more viable?
>
> M.
>
> po 15. 4. 2019 v 15:17 odesílatel Zoltan Farkas <zolyfarkas@yahoo.com <ma...@yahoo.com>> napsal:
> It is possible to do it with a custom JsonDecoder.
>
> I wrote one that does this at: https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java <https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java>
>
> hope it helps.
>
>
> —Z
>
>> On Apr 13, 2019, at 9:24 AM, Martin Mucha <alfonz19@gmail.com <ma...@gmail.com>> wrote:
>>
>> Hi,
>>
>> is it possible by design to deserialize JSON with schema having optional value?
>> Schema:
>>
>> {
>> "type" : "record",
>> "name" : "UserSessionEvent",
>> "namespace" : "events",
>> "fields" : [ {
>> "name" : "username",
>> "type" : "string"
>> }, {
>> "name" : "errorData",
>> "type" : [ "null", "string" ],
>> "default" : null
>> }]
>> }
>> Value to deserialize:
>> {"username" : "2271AE67-34DE-4B43-8839-07216C5D10E1"}
>> I also tried to change order of type, but that changed nothing. I know I can produce ill-formated JSON which could be deserialized, but that's not acceptable. AFAIK given JSON with required `username` and optional `errorData` cannot be deserialized by design. Am I right?
>>
>> thanks.
>
Re: is it possible to deserialize JSON with optional field?
Posted by Martin Mucha <al...@gmail.com>.
Hi, thanks for responding.
I know that you promote your fork, however considering I might not be able
to move away from "official release", is there an easy way how to consume
this? Since I cannot see it ...
Maybe side question: official avro seems to be dead. There are some commits
made, but last release happened 2 years ago, fatal flaws are not being
addressed, almost 10 years old valid bug reports are just ignored, ... Does
anyone know about any sign/confirmation that avro community will be moving
toward something more viable?
M.
po 15. 4. 2019 v 15:17 odesílatel Zoltan Farkas <zo...@yahoo.com>
napsal:
> It is possible to do it with a custom JsonDecoder.
>
> I wrote one that does this at:
> https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java
>
>
> hope it helps.
>
>
> —Z
>
> On Apr 13, 2019, at 9:24 AM, Martin Mucha <al...@gmail.com> wrote:
>
> Hi,
>
> is it possible by design to deserialize JSON with schema having optional
> value?
> Schema:
>
> {
> "type" : "record",
> "name" : "UserSessionEvent",
> "namespace" : "events",
> "fields" : [ {
> "name" : "username",
> "type" : "string"
> }, {
> "name" : "errorData",
> "type" : [ "null", "string" ],
> "default" : null
> }]}
>
> Value to deserialize:
>
> {"username" : "2271AE67-34DE-4B43-8839-07216C5D10E1"}
>
> I also tried to change order of type, but that changed nothing. I know I
> can produce ill-formated JSON which could be deserialized, but that's not
> acceptable. AFAIK given JSON with required `username` and optional
> `errorData` cannot be deserialized by design. Am I right?
>
> thanks.
>
>
>
Re: is it possible to deserialize JSON with optional field?
Posted by Zoltan Farkas <zo...@yahoo.com>.
It is possible to do it with a custom JsonDecoder.
I wrote one that does this at: https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java <https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java>
hope it helps.
—Z
> On Apr 13, 2019, at 9:24 AM, Martin Mucha <al...@gmail.com> wrote:
>
> Hi,
>
> is it possible by design to deserialize JSON with schema having optional value?
> Schema:
>
> {
> "type" : "record",
> "name" : "UserSessionEvent",
> "namespace" : "events",
> "fields" : [ {
> "name" : "username",
> "type" : "string"
> }, {
> "name" : "errorData",
> "type" : [ "null", "string" ],
> "default" : null
> }]
> }
> Value to deserialize:
> {"username" : "2271AE67-34DE-4B43-8839-07216C5D10E1"}
> I also tried to change order of type, but that changed nothing. I know I can produce ill-formated JSON which could be deserialized, but that's not acceptable. AFAIK given JSON with required `username` and optional `errorData` cannot be deserialized by design. Am I right?
>
> thanks.