| Meta model generator doesn't generate attribute in meta model if a custom type is used that doesn't declare Serializable itself but inherits from a class that implements Serializable. There is a workaround to just repeat the declaration of Serializable in the custom type. I've tracked down the issue to the class mentioned below more specifically the line:
for ( TypeMirror mirror : typeElement.getInterfaces() ) {
The code only checks the class of the type and does not inspect the super type. The code should be modified to check the interfaces declared in the super class(es). Additionally I wonder if the assumption that the custom value type must implement serializable is correct. I understand it's recommended and logically a value type should probably be serializable. Maybe to be reconsidered? I've included the source of the inner class BasicAttributeVisitor part of MetaAttributeGenerationVisitor in which I found the issue here:
class BasicAttributeVisitor extends SimpleTypeVisitor6<Boolean, Element> {
private final Context context;
public BasicAttributeVisitor(Context context) {
this.context = context;
}
@Override
public Boolean visitPrimitive(PrimitiveType t, Element element) {
return Boolean.TRUE;
}
@Override
public Boolean visitArray(ArrayType t, Element element) {
TypeMirror componentMirror = t.getComponentType();
TypeElement componentElement = (TypeElement) context.getTypeUtils().asElement( componentMirror );
return Constants.BASIC_ARRAY_TYPES.contains( componentElement.getQualifiedName().toString() );
}
@Override
public Boolean visitDeclared(DeclaredType declaredType, Element element) {
if ( ElementKind.ENUM.equals( element.getKind() ) ) {
return Boolean.TRUE;
}
if ( ElementKind.CLASS.equals( element.getKind() ) || ElementKind.INTERFACE.equals( element.getKind() ) ) {
TypeElement typeElement = ( (TypeElement) element );
String typeName = typeElement.getQualifiedName().toString();
if ( Constants.BASIC_TYPES.contains( typeName ) ) {
return Boolean.TRUE;
}
if ( TypeUtils.containsAnnotation( element, Constants.EMBEDDABLE ) ) {
return Boolean.TRUE;
}
for ( TypeMirror mirror : typeElement.getInterfaces() ) {
TypeElement interfaceElement = (TypeElement) context.getTypeUtils().asElement( mirror );
if ( "java.io.Serializable".equals( interfaceElement.getQualifiedName().toString() ) ) {
return Boolean.TRUE;
}
}
}
return Boolean.FALSE;
}
}
|