avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nandor Kollar (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (AVRO-2107) Unable to deserialize JSON with array type to GenericRecord
Date Thu, 07 Dec 2017 15:26:00 GMT

     [ https://issues.apache.org/jira/browse/AVRO-2107?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Nandor Kollar resolved AVRO-2107.
---------------------------------
    Resolution: Not A Bug

> Unable to deserialize JSON with array type to GenericRecord
> -----------------------------------------------------------
>
>                 Key: AVRO-2107
>                 URL: https://issues.apache.org/jira/browse/AVRO-2107
>             Project: Avro
>          Issue Type: Bug
>    Affects Versions: 1.8.1, 1.8.2
>            Reporter: Darshan Mehta
>         Attachments: sample.json, test-schema.avsc
>
>
> I am trying to deserialise the json with array type into GenericRecord and I get the
following exception:
> {code:java}
> Exception in thread "main" org.apache.avro.AvroTypeException: Unknown union branch sampleArrayRecordString
> 	at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:445)
> 	at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:290)
> 	at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
> 	at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:267)
> 	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:179)
> 	at org.apache.avro.generic.GenericDatumReader.readArray(GenericDatumReader.java:266)
> 	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:177)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:232)
> 	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:222)
> 	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:175)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:179)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:232)
> 	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:222)
> 	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:175)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
> 	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:145)
> 	at a.b.c.d.Test2.main(Test2.java:19)
> {code}
> Below is the code:
> {code:java}
> final Schema schema = Schema.parse(new File(
> 		"<schema_file_path>"));
> byte[] payload = Files.readAllBytes(Paths.get(
> 		"<json_file_path>"));
> GenericRecord record = new GenericDatumReader<GenericRecord>(schema).read(null,
> 		DecoderFactory.get().jsonDecoder(schema, new String(payload)));
> System.out.println(record);
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message