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

(ReflectData) Support for generic types in protocol definitions

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.9.0
    • Component/s: java
    • Labels:
      None

      Description

      For a Java interface extending another interface with type parameters, we may resolve actual type parameters and build the protocol definition based upon those.

      For example, let's say we have a generic protocol defined by a Java interface:

      public interface CrudProto<T, I> {
        void persist(T record);
      
        T fetchById(I id);
      }

      It would be natural to define a set of interfaces that extend this, such as:

      public interface FooBarRecordProto extends CrudProto<FooBarRecord, String> {}
      
      public interface OtherRecordProto extends CrudProto<OtherRecord, Long> {}
      

      Calling ReflectData.get().getProtocol(FooBarRecordProto.class) should be able to resolve that this protocol deals in FooBarRecords and Strings, and build a protocol accordingly.

      Currently, this call will produce an exception stating that a schema for 'T' cannot be resolved.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                igreene Ivan Greene
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: