Closed amorimjuliana closed 5 years ago
Thank you for reporting this -- I hope to evaluate and merge patch (#170) for inclusion in 2.10.
Rebased #176 for 2.10
@amorimjuliana @marcospassos Thank you for reporting the problem, contributing fix -- this should be resolved in 2.10.0.pr2 (released I hope by end of August)!
I did have to do minor tweaking to eliminate now unused method variants that do not take forValue
(handling of null
wrt schema, for the new test, introduced some edge condition... not sure I handled it right). But I assume things work reasonably well at any rate.
Thank you, @cowtowncoder!
@cowtowncoder Sorry for using this thread, but this is the closest issue I found to what I am having.
I'm trying to serialize a HashMap
with a Union Schema of 2 totally different records. Even though one of them fits the map structure, I receive the same error as the OP: Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Multiple Record and/or Map types, can not figure out which to use for
.
I'm using the same schema in Python and it works seamlessly. Am I doing something wrong?
Example of the map:
final Map<String, Object> obj = new HashMap<>();
obj.put("date", 19166);
obj.put("recipient", "xxx");
obj.put("member_id", "yyy");
obj.put("server", "zzz");
Jackson code block:
final ObjectWriter mapper = new AvroMapper().writer(new AvroSchema(schema));
return mapper.writeValueAsBytes(obj);
Schema:
[
{
"type":"record",
"name":"type_a",
"fields":[
{
"name":"date",
"type":[
"null",
{
"type":"int",
"logicalType":"date"
}
],
"default":null
},
{
"name":"recipient",
"type":"string"
},
{
"name":"member_id",
"type":[
"null",
"string"
],
"default":null
},
{
"name":"server",
"type":[
"null",
"string"
],
"default":null
},
...
I didn't post the whole schema because it is very long, but it is essentially an array with more records of different structures
As things are, this usage is not supported by Jackson Avro module: handling of Union types is difficult and what we would need here is to make Avro backend use Polymorphic Type handling of jackson-databind
. So in theory it would be possible to support, but in practice it is quite difficult... since information here comes from Schema and not types themselves.
So for time being unfortunately this would be "unsupported capability of Avro".
I believe this is a different issue from #123 and #164.
In the following example, we have a union schema with 5 record schemas and an abstract class annotated with
@Union
as follows:Problem 1: serialize as a concrete class and deserialize as an abstract class
When we serialize a value using the concrete class
ClassA
and then try to deserialize it as theAbstractClass
, we get the following error:Although serializing and then deserializing the class using the concrete class
ClassA
works.Problem 2: serialize as an abstract class
Also, the serialization using the abstract class
AbstractClass
does not work:I believe that both cases are valid and should not cause errors, or maybe I'm missing something.