From 11d28c0904ece1dc45cd191510038d8b81ba0507 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 3 Jul 2020 14:39:19 +0200 Subject: [PATCH] Added and committed an initial step to support Jackson 2.11.X --- .../utils/ElementMapper.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/org/gcube/informationsystem/utils/ElementMapper.java b/src/main/java/org/gcube/informationsystem/utils/ElementMapper.java index 0c38794..b82de92 100644 --- a/src/main/java/org/gcube/informationsystem/utils/ElementMapper.java +++ b/src/main/java/org/gcube/informationsystem/utils/ElementMapper.java @@ -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 superClass = null; + Class[] interfaces = clz.getInterfaces(); + for(Class interfaceClass : interfaces) { + if(Element.class.isAssignableFrom(interfaceClass)) { + try { + superClass = (Class) 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; } }