[
https://issues.apache.org/jira/browse/AVRO-2137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16780913#comment-16780913
]
Zoltan Farkas edited comment on AVRO-2137 at 2/28/19 9:06 PM:
--
I am not seeing this in my fork (https://github.com/zolyfarkas/avro), can you
please review my attempt to reproduce the issue?:
{code}
package org.apache.avro.io;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.junit.Test;
public class JsonDecoderTest {
private static final String SCHEMA
= "{\n" +
" \"type\": \"record\",\n" +
" \"name\": \"test\",\n" +
" \"namespace\": \"test.name\",\n" +
" \"fields\": [\n" +
"{\n" +
" \"name\": \"items\",\n" +
" \"type\": {\n" +
"\"type\": \"array\",\n" +
"\"items\": {\n" +
" \"type\": \"record\",\n" +
" \"name\": \"items\",\n" +
" \"fields\": [\n" +
"{\n" +
" \"name\": \"name\",\n" +
" \"type\": \"string\"\n" +
"},\n" +
"{\n" +
" \"name\": \"state\",\n" +
" \"type\": \"string\"\n" +
"}\n" +
" ]\n" +
"}\n" +
" }\n" +
"},\n" +
"{\n" +
" \"name\": \"firstname\",\n" +
" \"type\": \"string\"\n" +
"}\n" +
" ]\n" +
"}";
private static final String testData = "{ \"items\": [\n" +
"\n" +
"{ \"name\": \"dallas\", \"state\": \"TX\", \"country\":\"USA\" }\n" +
"\n" +
"], \"firstname\":\"fname\", \"lastname\":\"lname\" }";
@Test
public void testDecoding() throws IOException {
Schema writerSchema = new Schema.Parser().parse(SCHEMA);
Schema readerSchema = writerSchema;
ByteArrayInputStream bis =
new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8));
Decoder decoder = DecoderFactory.get().jsonDecoder(writerSchema, bis);
GenericDatumReader reader = new GenericDatumReader(writerSchema,
readerSchema);
GenericRecord testData = (GenericRecord) reader.read(null, decoder);
System.out.println(testData);
}
}
{code}
this might be caused by the fact that my fork contains the fix for:
https://issues.apache.org/jira/browse/AVRO-2057...
or that my attempt to reproduce is broken...
was (Author: zolyfarkas):
I am not seeing this in my fork (https://github.com/zolyfarkas/avro), can you
please review my attempt to reproduce the issue?:
{code}
package org.apache.avro.io;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.junit.Test;
public class JsonDecoderTest {
private static final String SCHEMA
= "{\n" +
" \"type\": \"record\",\n" +
" \"name\": \"test\",\n" +
" \"namespace\": \"test.name\",\n" +
" \"fields\": [\n" +
"{\n" +
" \"name\": \"items\",\n" +
" \"type\": {\n" +
"\"type\": \"array\",\n" +
"\"items\": {\n" +
" \"type\": \"record\",\n" +
" \"name\": \"items\",\n" +
" \"fields\": [\n" +
"{\n" +
" \"name\": \"name\",\n" +
" \"type\": \"string\"\n" +
"},\n" +
"{\n" +
" \"name\": \"state\",\n" +
" \"type\": \"string\"\n" +
"}\n" +
" ]\n" +
"}\n" +
" }\n" +
"},\n" +
"{\n" +
" \"name\": \"firstname\",\n" +
" \"type\": \"string\"\n" +
"}\n" +
" ]\n" +
"}";
private static final String testData = "{ \"items\": [\n" +
"\n" +
"{ \"name\": \"dallas\", \"state\": \"TX\", \"country\":\"USA\" }\n" +
"\n" +
"], \"firstname\":\"fname\", \"lastname\":\"lname\" }";
@Test
public void testDecoding() throws IOException {
Schema writerSchema = new Schema.Parser().parse(SCHEMA);
Schema readerSchema = writerSchema;
ByteArrayInputStream bis =
new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8));
Decoder decoder = DecoderFactory.get().jsonDecoder(writerSchema, bis);
GenericDatumReader reader = new GenericDatumReader(writerSchema,
readerSchema);
GenericRecord testData = (GenericRecord) reader.read(null, decoder);
System.out.println(testData);
}
}
{code}
this might be caused by the fact that contains the fix for:
https://issues.apache.org/jira/browse/AVRO-2057...
or that my attempt to reproduce is broken...
> avro JsonDecoding additional field in array type
>
>
> Key: AVRO-2137
> URL: https://issues.apache.org/jira/browse/AVRO-2137
> Project: Apache Avro
> Issue Type: Bug
>