From 1b3fe81b61bd1bb5f6286d6288e7f99a618517a2 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 24 Mar 2016 13:16:25 +0100 Subject: [PATCH] DATAREDIS-482 - Provide meaningful exception messages in MappingRedisConverter. Original pull request: #183. --- .../redis/core/convert/MappingRedisConverter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java b/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java index ddb345e7c..87f16256e 100644 --- a/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java +++ b/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java @@ -509,6 +509,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean { } if (customConversions.hasCustomWriteTarget(value.getClass())) { + Class targetType = customConversions.getCustomWriteTarget(value.getClass()); if (ClassUtils.isAssignable(Map.class, targetType)) { @@ -521,9 +522,9 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean { } else if (ClassUtils.isAssignable(byte[].class, targetType)) { sink.getBucket().put(path, toBytes(value)); } else { - throw new IllegalArgumentException("converter must not fool me!!"); + throw new IllegalArgumentException( + String.format("Cannot convert value '%s' of type %s to bytes.", value, value.getClass())); } - } } @@ -634,7 +635,8 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean { Matcher matcher = pattern.matcher(entry.getKey()); if (!matcher.find()) { - throw new RuntimeException("baähhh"); + throw new IllegalArgumentException( + String.format("Cannot extract map value for key '%s' in path '%s'.", entry.getKey(), path)); } String key = matcher.group(2); target.put(key, fromBytes(entry.getValue(), valueType)); @@ -665,7 +667,8 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean { Matcher matcher = pattern.matcher(key); if (!matcher.find()) { - throw new RuntimeException("baähhh"); + throw new IllegalArgumentException( + String.format("Cannot extract map value for key '%s' in path '%s'.", key, path)); } String mapKey = matcher.group(2);