Improved unmarshalling in ElementMapper

This commit is contained in:
Luca Frosini 2023-05-17 18:12:34 +02:00
parent f9137ffff9
commit 1368f707c8
1 changed files with 29 additions and 9 deletions

View File

@ -312,7 +312,11 @@ public abstract class ElementMapper {
} }
JsonNode jsonNode = mapper.readTree(reader); JsonNode jsonNode = mapper.readTree(reader);
jsonNode = analizeTypes((ObjectNode) jsonNode); jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)); return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
} }
} }
@ -336,7 +340,11 @@ public abstract class ElementMapper {
} }
JsonNode jsonNode = mapper.readTree(stream); JsonNode jsonNode = mapper.readTree(stream);
jsonNode = analizeTypes((ObjectNode) jsonNode); jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)); return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
} }
} }
@ -359,7 +367,11 @@ public abstract class ElementMapper {
} }
JsonNode jsonNode = mapper.readTree(string); JsonNode jsonNode = mapper.readTree(string);
jsonNode = analizeTypes((ObjectNode) jsonNode); jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)); return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
} }
} }
@ -374,10 +386,14 @@ public abstract class ElementMapper {
} }
List<El> ret = new ArrayList<>(); List<El> ret = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string); ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
try {
for(JsonNode jsonNode : arrayNode) { for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeTypes((ObjectNode) jsonNode); jsonNode = analizeTypes((ObjectNode) jsonNode);
ret.add(ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode))); ret.add(ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)));
} }
}catch (Throwable t) {
throw e;
}
return ret; return ret;
} }
} }
@ -390,10 +406,14 @@ public abstract class ElementMapper {
} catch (InvalidTypeIdException e) { } catch (InvalidTypeIdException e) {
List<El> ret = new ArrayList<>(); List<El> ret = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string); ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
try {
for(JsonNode jsonNode : arrayNode) { for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeTypes((ObjectNode) jsonNode); jsonNode = analizeTypes((ObjectNode) jsonNode);
ret.add((El) ElementMapper.unmarshal(Element.class, mapper.writeValueAsString(jsonNode))); ret.add((El) ElementMapper.unmarshal(Element.class, mapper.writeValueAsString(jsonNode)));
} }
}catch (Throwable t) {
throw e;
}
return ret; return ret;
} }
} }