I write here as I'm having problems to deserialise a Record type in Java when is inside a union of two Records and I didn't find any similar post.
I would like to ask, is anyone of you face this problem and/or can help me to find a solution??
The avro schema that we defined is with a EventWrapper like this:
{
"type": "record",
"name": "EventWrapper",
"namespace": "com.my.spec.avro.wrapper",
"fields": [{
"name": "delta",
"type": "null",
"default": null
},{
"name": "data",
"type": [
"null",
{
"type": "record",
"name": "PersonEventDto",
"namespace": "com.my.spec.avro.entity",
"fields":[
.....
]
},{
"type": "record",
"name": "CustomerEventDto",
"namespace": "com.my.spec.avro.entity",
"fields": [
.....
]
}
],
"default": null
}
]
}
The idea is to have delta and data, both of them nullable and, by the moment, we defined two records in the field of data. PersonEventDto and CustomerEventDto.
The problem is that the plugin avro-maven-plugin converts this union data to Object in java and it doesn’t keep the type anywhere.
private java.lang.Object data;
And when we want to deserialise it using this EventWrapper object generated from the avro maven plugin and we can’t get the data object with its real type. (PersonEventDto and CustomerEventDto.)
Anyone faced this problem with record and unions? Is there a way that avro or maven plugin keeps the types to have it in the serialization or deserialization?
Thanks you in advance!