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

Sachin Goyal commented on AVRO-1571:
------------------------------------

If we pass an obj of type 'ParentContext' to ReflectData#createSchema() (and 
couple of their downstream functions), following schema can be generated.

{code:javascript}
{
  "type" : "record",
  "name" : "ParameterTypes",
  "namespace" : "org.apache.avro.reflect",
  "fields" : [ {
    "name" : "m1",
    "type" : {
      "type" : "record", "name" : "Master1",
      "fields" : [ {
        "name" : "foo",
        "type" : {
          "type" : "record", "name" : "Foo10b2274d0c76a664",
          "fields" : [ {"name" : "p","type" : "int"}, {"name" : "q", "type" : 
"long"} ]
        } } ] }
  }, {
    "name" : "m2",
    "type" : {
      "type" : "record", "name" : "Master2",
      "fields" : [ {
        "name" : "foo",
        "type" : {
          "type" : "record", "name" : "Foo20f193d415184f4e",
          "fields" : [ {"name" : "p","type" : "string"}, {"name" : "q", "type" 
: "string"} ]
        } } ] }
  }, {
    "name" : "m3",
    "type" : {
      "type" : "record", "name" : "Master31830bfd9460d8d21",
      "fields" : [ {
        "name" : "foo",
        "type" : {
          "type" : "record", "name" : "Foo14b15d58d3be921d",
          "fields" : [ {"name" : "p","type" : "int"}, {"name" : "q", "type" : 
"int"} ]
        } } ] }
  } ]
}
{code}

\\
Note that:
# The record Foo might need to have its name mangled as clazz.getSimpleName() + 
Hash64 (param-names)
# When serializing the actual object, the same ParentConext would need to be 
passed along the write calls as well.
\\
\\

> Support parameterized types in Avro
> -----------------------------------
>
>                 Key: AVRO-1571
>                 URL: https://issues.apache.org/jira/browse/AVRO-1571
>             Project: Avro
>          Issue Type: Bug
>    Affects Versions: 1.7.6
>            Reporter: Sachin Goyal
>
> The below code cannot be serialized by Avro.
> {code}
> class ParameterTypes {
>   Master1 m1;
>   Master2 m2;
>   Master3<Integer> m3;
> }
> class Foo <P, Q> {
>   P p;
>   Q q;
> }
> class Master1 {
>   Foo <Integer, Long> foo;
> }
> class Master2 {
>   Foo <String, String> foo;
> }
> class Master3 <P> {
>   Foo <P, P> foo;
> }
> {code}
> This is because when generating the schema, only the current class is used to 
> generate the schema. The parent class' context is missing in 
> ReflectData#createSchema() functions where the actual type-information is 
> present.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to