Amit Kumar created AVRO-2502:
--------------------------------
Summary: Handle common schema in avro while generating code using
avro maven plugin
Key: AVRO-2502
URL: https://issues.apache.org/jira/browse/AVRO-2502
Project: Apache Avro
Issue Type: New Feature
Reporter: Amit Kumar
Using avro maven plugin to generate java code for avro .avsc schema file, there
is one common schema which is getting used at multiple places as separate
records, when i give different namespace at each place, it is able to generate
java code, but generated code is in different folders although code for both
classes are same
Is there any way to generate only single class for common reference like above
schenario... Here is example avsc
{code:java}
{
"namespace": "exmaple.avro",
"type": "record",
"name": "TopRecord",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "AC",
"type": {
"type": "record",
"name": "AC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}, {
"name": "BC",
"type": {
"type": "record",
"name": "BC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}
]
}
{code}
If i give different namespaces for InnerCommon schema at both placed, it is
able to generate code but with classes in 2 folders which have same code :(
Here is working avsc with namespace
{code:java}
{
"namespace": "exmaple.avro",
"type": "record",
"name": "TopRecord",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "AC",
"type": {
"type": "record",
"name": "AC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"namespace": "inner1",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}, {
"name": "BC",
"type": {
"type": "record",
"name": "BC_SCHEMA",
"fields": [{
"name": "id",
"type": "string"
},
{
"name": "amount",
"type": "double"
},
{
"name": "InnerCommon",
"type": {
"type": "record",
"name": "InnerSchema",
"namespace": "inner2",
"fields": [{
"name": "id",
"type": "string"
}]
}
}
]
}
}
]
}
{code}
Here is the generated folder structure
!Screenshot 2019-08-08 at 8.52.22 AM.png!
Add folder for having only 1 folder where we can have single java file
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)