avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Lord (Created) (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AVRO-1066) ArrayIndexOutOfBoundsException in ParsingEncoder when trying to use a json encoder to serialize a deep object graph
Date Thu, 19 Apr 2012 00:04:41 GMT
ArrayIndexOutOfBoundsException in ParsingEncoder when trying to use a json encoder to serialize
a deep object graph
-------------------------------------------------------------------------------------------------------------------

                 Key: AVRO-1066
                 URL: https://issues.apache.org/jira/browse/AVRO-1066
             Project: Avro
          Issue Type: Bug
            Reporter: Daniel Lord


I have an avro record that can have an array of children records of the same type.  If this
structure gets to be too deep then I continually get an ArrayOutOfBoundsException in ParsingEncoder
when trying to use a json encoder.  This works fine when using a binary encoder.  My schema
looks something like this: 

{
    "name" : "MyRecord",
    "type" : "record",
    "fields" : [
        {
            "name" : "fooField",
            "type" : "int"
        },
        {
            "name" : "childRecords",
            "type" : [ "null", { "type" : "array", "items" : "MyRecord" } ]
        }
    ]
}

The code I'm using to capture a JSON string for debugging looks like this: 

        ByteArrayOutputStream os = null;
        try {
            os = new ByteArrayOutputStream(2048);
            final Encoder jsonEncoder = EncoderFactory.get().jsonEncoder(MyRecord.SCHEMA$,
os);
            final DatumWriter<MyRecord> datumWriter = new SpecificDatumWriter<MyRecord>(MyRecord.class);
            datumWriter.write(record, jsonEncoder);
            jsonEncoder.flush();

            return new String(os.toByteArray(), Charset.defaultCharset());

        } catch (IOException e) {
            return null;
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                }
            }
        }

The error I get looks like this: 
java.lang.ArrayIndexOutOfBoundsException: 10
	at org.apache.avro.io.ParsingEncoder.push(ParsingEncoder.java:55)
	at org.apache.avro.io.JsonEncoder.writeArrayStart(JsonEncoder.java:231)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:125)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:129)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:67)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:57)
<my line calling datumWriter.write> 


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message