Added and committed an initial step to support Jackson 2.11.X

This commit is contained in:
Luca Frosini 2020-07-03 14:39:19 +02:00
parent 278e10e548
commit 11d28c0904
1 changed files with 25 additions and 0 deletions

View File

@ -314,6 +314,29 @@ public abstract class ElementMapper {
return mapper.readValue(string, clz);
} catch(InvalidTypeIdException e) {
String typeId = e.getTypeId();
/* An initial step to support the Jackson 2.11
if(knownTypes.containsKey(typeId)) {
// problem of type is not subtype of itself
Class<? extends Element> superClass = null;
Class<?>[] interfaces = clz.getInterfaces();
for(Class<?> interfaceClass : interfaces) {
if(Element.class.isAssignableFrom(interfaceClass)) {
try {
superClass = (Class<? extends Element>) interfaceClass;
return (ISM) ElementMapper.unmarshal(superClass, string);
}catch (Exception ex) {
// Trying the next type
logger.error("", e);
}
}
}
throw e;
}
*/
JsonNode jsonNode = mapper.readTree(string);
try {
jsonNode = analizeJsonToReplaceType(jsonNode, typeId);
@ -321,6 +344,8 @@ public abstract class ElementMapper {
throw e;
}
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
} catch (Exception e) {
throw e;
}
}