FASTJson2 version --> 2.0.37
I went through the code and found these problematic pieces,
In ObjectReaderCreator class, under createObjectReader method, the following piece of code creates an instance for ObjectReaderInterface.
if (objectClass.isInterface()) {
return new ObjectReaderInterface(
objectClass,
null,
null,
0L,
null,
null,
fieldReaderArray
);
}
There is no beanInfo.typeKey reference in the parameters. So the type information is lost. The below change adds the information from beanInfo class to the parameters.
if (objectClass.isInterface()) {
return new ObjectReaderInterface(
objectClass,
beanInfo.typeKey,
null,
beanInfo.readerFeatures,
null,
null,
fieldReaderArray
);
}
The above is required for this condition in ObjectReaderInterface class
In ObjectReaderBaseModule.ReaderAnnotationProcessor class, there are two changes required. The first is handling interfaces and the other is for superClass in the getBeanInfo method. Below are the rough changes I have made. The superClass code piece is required to handle any annotation on the super class. Right now if I take an abstract class and add an annotation to that, it is not recognized (for example create an abstract class called AbstractDataFrameFunctionConfig and add the @JsonTypeInfo annotation to that and then try to deserialize it. Keep the hierarchy the same, just change it from interface to abstract)
Class superClass = objectClass.getSuperclass();
if (superClass != null && superClass != Object.class && superClass != Enum.class) {
getBeanInfo(beanInfo, superClass);
}
Class<?>[] interfaces = objectClass.getInterfaces();
if (interfaces.length > 0) {
for (Class<?> superInterface : interfaces) {
getBeanInfo(beanInfo, superInterface);
}
}
In ObjectWriterBaseModule.WriterAnnotationProcessor getBeanInfo method added the following change
if (objectClass != null) {
Class superclass = objectClass.getSuperclass();
if (superclass != Object.class && superclass != null && superclass != Enum.class) {
getBeanInfo(beanInfo, superclass);
if (beanInfo.seeAlso != null && beanInfo.seeAlsoNames != null) {
for (int i = 0; i < beanInfo.seeAlso.length; i++) {
Class seeAlso = beanInfo.seeAlso[i];
if (seeAlso == objectClass && i < beanInfo.seeAlsoNames.length) {
String seeAlsoName = beanInfo.seeAlsoNames[i];
if (seeAlsoName != null && seeAlsoName.length() != 0) {
beanInfo.typeName = seeAlsoName;
break;
}
}
}
}
}
Class<?>[] interfaces = objectClass.getInterfaces();
if (interfaces.length > 0) {
for (Class<?> superInterface : interfaces) {
getBeanInfo(beanInfo, superInterface);
if (beanInfo.seeAlso != null && beanInfo.seeAlsoNames != null) {
for (int i = 0; i < beanInfo.seeAlso.length; i++) {
Class seeAlso = beanInfo.seeAlso[i];
if (seeAlso == objectClass && i < beanInfo.seeAlsoNames.length) {
String seeAlsoName = beanInfo.seeAlsoNames[i];
if (seeAlsoName != null && seeAlsoName.length() != 0) {
beanInfo.typeName = seeAlsoName;
break;
}
}
}
}
}
}
}
With the above changes, I am able to get the expected output.
Code sample -
RuntimeConfigVeryShort.json file
Expected Output -
Actual Output -
FASTJson2 version --> 2.0.37 I went through the code and found these problematic pieces, In ObjectReaderCreator class, under createObjectReader method, the following piece of code creates an instance for ObjectReaderInterface.
There is no beanInfo.typeKey reference in the parameters. So the type information is lost. The below change adds the information from beanInfo class to the parameters.
The above is required for this condition in ObjectReaderInterface class
In ObjectReaderBaseModule.ReaderAnnotationProcessor class, there are two changes required. The first is handling interfaces and the other is for superClass in the getBeanInfo method. Below are the rough changes I have made. The superClass code piece is required to handle any annotation on the super class. Right now if I take an abstract class and add an annotation to that, it is not recognized (for example create an abstract class called AbstractDataFrameFunctionConfig and add the @JsonTypeInfo annotation to that and then try to deserialize it. Keep the hierarchy the same, just change it from interface to abstract)
In ObjectWriterBaseModule.WriterAnnotationProcessor getBeanInfo method added the following change
With the above changes, I am able to get the expected output.