The serialization mechanism currently calls the ReflectData.get().resolveUnion() Method for resolving union schemas. This call represents a huge penalty as it generates the entire schema for the object behind the scenes to get the schema name and find the corresponding index. It's even worse because sometimes it not even possible to generate the schema for the actual value, causing the serialization to fail:
class Foo {
// The schema for this object cannot be generated, as the type of tricks can be anything.
// However, for the sake of the serialization, it doesn't matter, as the type has been specified in the schema
public Set<?> tricks = new HashSet<>();
}
This issue can be resolved by checking the set of union schema using the class name instead of using ReflectData.get().resolveUnion(). There is already a snippet in the code that does exactly this, but is currently disabled.
The serialization mechanism currently calls the
ReflectData.get().resolveUnion()
Method for resolving union schemas. This call represents a huge penalty as it generates the entire schema for the object behind the scenes to get the schema name and find the corresponding index. It's even worse because sometimes it not even possible to generate the schema for the actual value, causing the serialization to fail:This issue can be resolved by checking the set of union schema using the class name instead of using
ReflectData.get().resolveUnion()
. There is already a snippet in the code that does exactly this, but is currently disabled.