Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.9.0
-
None
-
None
Description
Inheritance and polymorphism are widely used in Java libraries. If multiple sophisticated Avro schema generator can be added to Avro, users can generate Avro schema easily for classes in complex context, third-party code and legacy code.
For example, for the following class:
public class TestReflectPolymorphismData { { public static class SuperclassA1 { private String SuperclassA1; } public static class SubclassA1 extends SuperclassA1 { private String SubclassA1; } public static class SubclassA2 extends SuperclassA1 { private String SubclassA2; } public static class SuperB1 { private SubclassA1 SubclassA1; private List<SubclassA2> SubclassA2List; private Map<String, SuperclassA1> stringSuperclassA1Map; private Map<Integer, SuperclassA1> integerSuperclassA1Map; } } }
It'll be good if Avro can provide a schema generator to generate a schema like the following automatically for class SuperB1 :
{ "type": "record", "name": "SuperB1", "namespace": "org.apache.avro.reflect.TestReflectPolymorphismData$", "fields": [ { "name": "SubclassA1", "type": { "type": "record", "name": "SuperclassA1", "fields": [ { "name": "SuperclassA1", "type": "string" }, { "name": "SuperclassA1Subclasses", "type": [ "null", { "type": "record", "name": "SubclassA1", "fields": [ { "name": "SubclassA1", "type": "string" } ] }, { "type": "record", "name": "SubclassA2", "fields": [ { "name": "SubclassA2", "type": "string" } ] } ] } ] } }, { "name": "SubclassA2List", "type": { "type": "array", "items": "SuperclassA1", "java-class": "java.util.List" } }, { "name": "stringSuperclassA1Map", "type": { "type": "map", "values": "SuperclassA1" } }, { "name": "integerSuperclassA1Map", "type": { "type": "array", "items": { "type": "record", "name": "Pair34255fab6d3d79ff", "namespace": "org.apache.avro.reflect", "fields": [ { "name": "key", "type": "int" }, { "name": "value", "type": "org.apache.avro.reflect.TestReflectPolymorphismData$.SuperclassA1" } ] }, "java-class": "java.util.Map" } } ] }
related story: AVRO-1568