Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.8.2
-
None
-
None
-
The working environment is Windows 10 with java 1.8 92 but I suspect this code will work on all systems.
Description
ReflectData produces 'invalid' type entries for Abstract objects. An example is InetAddress. What it produces is valid JSON but the schema cannot be used to deserialize/read the serialized/write output. ReflectData produces is
{"type":"record","name":"InetAddress","namespace":"java.net","fields":[]}but it should notice that InetAddress is an abstract class and go find the classes that extend the class.
{"type":"record","name":"Inet4Address","namespace":"java.net","fields":[]},{"type":"record","name":"Inet6Address","namespace":"java.net","fields":[]}
I have a current workaround for this with the following, but it is a little hacky and not that efficient if used alot.
private static String abstractInetAddress = "{\"type\":\"record\",\"name\":\"InetAddress\",\"namespace\":\"java.net\",\"fields\":[]}";
private static String abstractInetAddressReplacement = //
"{\"type\":\"record\",\"name\":\"Inet4Address\",\"namespace\":\"java.net\",\"fields\":[]}" + //
",{\"type\":\"record\",\"name\":\"Inet6Address\",\"namespace\":\"java.net\",\"fields\":[]}";
public AvroUtil(Class<T> clazz) {
schema = ReflectData.AllowNull.get().getSchema(clazz);
String s = schema.toString().replace(abstractInetAddress, abstractInetAddressReplacement);
schema = new Schema.Parser().parse(s);
this.clazz = clazz;
}