[ 
https://issues.apache.org/jira/browse/AVRO-4274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18101405#comment-18101405
 ] 

Zachary Payne commented on AVRO-4274:
-------------------------------------

[~rskraba] my team is looking to prioritize this contribution back to Avro in 
the next couple of months. Are the proposed changes to the output for Java 
Generics acceptable?

> Add Support for Java Generics in ReflectData
> --------------------------------------------
>
>                 Key: AVRO-4274
>                 URL: https://issues.apache.org/jira/browse/AVRO-4274
>             Project: Apache Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Zachary Payne
>            Assignee: Ryan Skraba
>            Priority: Minor
>
> {{ReflectData}} generates schema by inspecting a class via reflection; when a 
> field's declared type is a parameterized type or a type variable (e.g. {{T}} 
> from a class {{{}Box<T>{}}}), {{ReflectData}} has no way to resolve those 
> type variables to their concrete types. The result is either a runtime error 
> or a schema that loses the type information entirely.
> My team has created an extended Avro Java library internally, and we've 
> produced a working implementation of this approach and have been running it 
> in production. Our extension includes single-level generics, multi-level 
> nesting, multiple type parameters, sealed class hierarchies, and union fields 
> with generic members. We'd like to contribute this extension of Avro back to 
> the open source code.
> All changes are additive. Existing non-generic classes follow the same code 
> paths as today.
> *Current Results:* (requires a concrete class {{{}HierarchyAString{}}})
> {code:java}
> {
>   "type" : "record",
>   "name" : "PojoWithGenericWithString",
>   "namespace" : "org.apache.avro.reflect.TestReflect",
>   "fields" : [ {
>     "name" : "myHierarchyA",
>     "type" : {
>       "type" : "record",
>       "name" : "HierarchyAString",
>       "fields" : [ {
>         "name" : "value",
>         "type" : "string"
>       } ]
>     }
>   } ]
> }
> {code}
> *Our Approach:* (supports a generic instead of a concrete class)
> {code:java}
> {
>   "type" : "record",
>   "name" : "PojoWithGenericWithString",
>   "namespace" : "[...].avro.model.sample.PojoGenerics",
>   "fields" : [ {
>     "name" : "myHierarchyA",
>     "type" : {
>       "type" : "record",
>       "name" : "HierarchyA_LB_String_RB_",
>       "fields" : [ {
>         "name" : "value",
>         "type" : "string"
>       } ],
>       "className" : "HierarchyA"
>     }
>   } ]
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to