Improved code

This commit is contained in:
Luca Frosini 2020-07-02 18:52:52 +02:00
parent f1d52d3b04
commit ef41afa38d
1 changed files with 20 additions and 19 deletions

View File

@ -82,14 +82,10 @@ public abstract class ElementMapper {
if(!Type.class.isAssignableFrom(clz)) {
Class<Element> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
SimpleModule isModule = new SimpleModule(accessType.getName());
isModule.addDeserializer(clz, new ElementDeserializer<>(clz, mapper));
mapper.registerModule(isModule);
ElementMapper.registerSubtypes(dummyClz);
}
/* else {
ElementMapper.registerSubtypes(clz, dummyClz);
}else {
ElementMapper.registerSubtypes(clz);
}*/
}
packages.add(clz.getPackage());
}
@ -123,20 +119,25 @@ public abstract class ElementMapper {
}
}
public static <El extends Element> void registerSubtypes(Class<El>... classes) {
for(Class<El> clz : classes) {
String typeName = TypeMapper.getType(clz);
knownTypes.put(typeName, clz);
public static <El extends Element> void registerSubtypes(Class<El> clz, Class<El> implementationClass) {
String typeName = TypeMapper.getType(clz);
SimpleModule isModule = new SimpleModule(typeName);
isModule.addDeserializer(clz, new ElementDeserializer<>(clz, mapper));
mapper.registerModule(isModule);
registerSubtypes(implementationClass);
}
public static <El extends Element> void registerSubtypes(Class<El> clz) {
String typeName = TypeMapper.getType(clz);
knownTypes.put(typeName, clz);
// if(clz.isAnnotationPresent(JsonDeserialize.class)) {
// JsonDeserialize jsonDeserialize = clz.getAnnotation(JsonDeserialize.class);
// Class<? extends ElementImpl> impl = (Class<? extends ElementImpl>) jsonDeserialize.as();
// nameToImplementation.put(typeName, impl);
// }
// if(clz.isAnnotationPresent(JsonDeserialize.class)) {
// JsonDeserialize jsonDeserialize = clz.getAnnotation(JsonDeserialize.class);
// Class<? extends ElementImpl> impl = (Class<? extends ElementImpl>) jsonDeserialize.as();
// nameToImplementation.put(typeName, impl);
// }
}
mapper.registerSubtypes(classes);
mapper.registerSubtypes(clz);
}
/**