Resolve element type from NodeType before falling back to reflection when reading values from JsonNode.

This commit changes the node value retrieval so that it first tries to determine the node type before falling back to reflective access of the _value field.

Closes #2838
Original pull request: #2842
This commit is contained in:
Christoph Strobl
2024-02-02 11:41:56 +01:00
committed by Mark Paluch
parent 2f34f63e28
commit 7fad17a1de

View File

@@ -436,8 +436,20 @@ public class Jackson2HashMapper implements HashMapper<Object, String, Object> {
} else if (element.isContainerNode()) {
doFlatten(propertyPrefix, element.fields(), resultMap);
} else {
resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element)
.getPropertyValue("_value"));
switch (element.getNodeType()) {
case STRING -> resultMap.put(propertyPrefix, element.textValue());
case NUMBER -> resultMap.put(propertyPrefix, element.numberValue());
case BOOLEAN -> resultMap.put(propertyPrefix, element.booleanValue());
case BINARY -> {
try {
resultMap.put(propertyPrefix, element.binaryValue());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
default -> resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value"));
}
}
}