Skip to content

Commit 7fad17a

Browse files
christophstroblmp911de
authored andcommitted
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
1 parent 2f34f63 commit 7fad17a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,20 @@ private void flattenElement(String propertyPrefix, Object source, Map<String, Ob
436436
} else if (element.isContainerNode()) {
437437
doFlatten(propertyPrefix, element.fields(), resultMap);
438438
} else {
439-
resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element)
440-
.getPropertyValue("_value"));
439+
440+
switch (element.getNodeType()) {
441+
case STRING -> resultMap.put(propertyPrefix, element.textValue());
442+
case NUMBER -> resultMap.put(propertyPrefix, element.numberValue());
443+
case BOOLEAN -> resultMap.put(propertyPrefix, element.booleanValue());
444+
case BINARY -> {
445+
try {
446+
resultMap.put(propertyPrefix, element.binaryValue());
447+
} catch (IOException e) {
448+
throw new IllegalStateException(e);
449+
}
450+
}
451+
default -> resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value"));
452+
}
441453
}
442454
}
443455

0 commit comments

Comments
 (0)