Uploaded image for project: 'Avro'
  1. Avro
  2. AVRO-2151

ReflectData, JsonEncoder encoding runtime exception

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8.2
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      Using reflect data has a problem if a field is an array of an object (eg String[]) and using JsonEncoder.

      SimpleĀ  reproduction of the problem

      public static class Record {
        private String[] myfield = new String[]{"hello world"};
      }
      
      public static void main(String[] args) throws IOException {
        Schema s = SchemaBuilder.record("Record")
          .fields()
            .name("myfield").type(
              Schema.createArray(
               Schema.create(Schema.Type.STRING)
              )
            ).noDefault()
          .endRecord();
      
        System.out.println(s);
      
        ReflectData d = new ReflectData();
        d.createDatumWriter(s).write(new Record(),   EncoderFactory.get().jsonEncoder(s, System.out, true));
      }
      
      org.apache.avro.AvroTypeException: Incorrect number of items written. 1 more required.
      	at org.apache.avro.io.ParsingEncoder.pop(ParsingEncoder.java:60)
      	at org.apache.avro.io.JsonEncoder.writeArrayEnd(JsonEncoder.java:259)
      	at org.apache.avro.reflect.ReflectDatumWriter.writeArray(ReflectDatumWriter.java:112)
      	at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:120)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:75)
      	at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:159)
      	at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:166)
      	at org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:90)
      	at org.apache.avro.reflect.ReflectDatumWriter.writeField(ReflectDatumWriter.java:191)
      	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:156)
      	at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:118)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:75)
      	at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:159)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:62)
      	at Bugged.main(Bugged.java:30)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              xushichang Xu ShiChang Desmond
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: