Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-18223

AvroSerializer does not correctly instantiate GenericRecord

    XMLWordPrintableJSON

    Details

      Description

      AvroSerializer.createInstance() simply calls InstantiationUtil.instantiate(type) to create a new instance, also when type is GenericRecord.

      This fails with an exception, because a GenericRecord must be instantiated through GenericRecordBuilder but InstantiationUtil is not aware of it.

      The class 'org.apache.avro.generic.GenericRecord' is not instantiable: The class is not a proper class. It is either abstract, an interface, or a primitive type.

      This can be proven with this test

      @Test
      public void shouldInstantiateGenericRecord() {
          org.apache.avro.Schema SCHEMA = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Dummy\",\"namespace\":\"dummy\",\"fields\":[{\"name\":\"something\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}]}");
          AvroSerializer<GenericRecord> serializer = new AvroSerializer<>(GenericRecord.class, SCHEMA);
      
          serializer.createInstance();
      }
      

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nicusX Lorenzo Nicora
                Reporter:
                nicusX Lorenzo Nicora
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: