Fixed getType

This commit is contained in:
Luca Frosini 2021-01-27 11:57:16 +01:00
parent af24bde831
commit a8e1b0da6e
1 changed files with 12 additions and 5 deletions

View File

@ -94,11 +94,15 @@ public class TypeMapper {
public static String getType(Class<? extends Element> clz){ public static String getType(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName(); String classSimpleName = clz.getSimpleName();
String name = null; String name = null;
if(clz.isAnnotationPresent(JsonTypeName.class)) {
JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class); if(!clz.isInterface()) {
name = jsonTypeName.value(); if(clz.isAnnotationPresent(JsonTypeName.class)) {
if(name==null || name.compareTo("")!=0) { JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class);
throw new RuntimeException("Invalid annotation @JsonTypeName for type " + classSimpleName); name = jsonTypeName.value();
if(name==null || name.compareTo("")==0) {
throw new RuntimeException("Invalid annotation @JsonTypeName for type " + classSimpleName);
}
return name;
} }
} }
@ -106,9 +110,11 @@ public class TypeMapper {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class); TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
String typeMetadataName = typeMetadata.name(); String typeMetadataName = typeMetadata.name();
if(typeMetadataName!=null && typeMetadataName.compareTo("")!=0) { if(typeMetadataName!=null && typeMetadataName.compareTo("")!=0) {
/*
if(name!=null && typeMetadataName.compareTo(name)!=0) { if(name!=null && typeMetadataName.compareTo(name)!=0) {
throw new RuntimeException("Name in annotation @TypeMetadata differ from annotation in @JsonTypeName for type " + classSimpleName + ". Please be coerent"); throw new RuntimeException("Name in annotation @TypeMetadata differ from annotation in @JsonTypeName for type " + classSimpleName + ". Please be coerent");
} }
*/
return typeMetadataName; return typeMetadataName;
}else { }else {
throw new RuntimeException("Invalid Name in annotation @TypeMetadata for type " + classSimpleName); throw new RuntimeException("Invalid Name in annotation @TypeMetadata for type " + classSimpleName);
@ -116,6 +122,7 @@ public class TypeMapper {
}else { }else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName); throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
} }
} }
public static String getTypeDescription(Class<? extends Element> clz){ public static String getTypeDescription(Class<? extends Element> clz){