From 7fad17a1deaa2ccbcd69ec5d151b2119bb16d7f5 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Fri, 2 Feb 2024 11:41:56 +0100 Subject: [PATCH] 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 --- .../data/redis/hash/Jackson2HashMapper.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java b/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java index 4c68825c9..e33243b6b 100644 --- a/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java @@ -436,8 +436,20 @@ public class Jackson2HashMapper implements HashMapper { } 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")); + } } }