From 4a7a485e628a7cf240bb076316f5da3ed0c157d4 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 23 Dec 2014 09:48:47 +0100 Subject: [PATCH] DATAMONGO-1118 - Simplified potentiallyConvertMapKey in MappingMongoConverter. Fixed typos in CustomConversions. Original pull request: #260. --- .../mongodb/core/convert/CustomConversions.java | 6 +++--- .../core/convert/MappingMongoConverter.java | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java index c3f953646..7115ef228 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java @@ -247,9 +247,9 @@ public class CustomConversions { } /** - * Returns the target type we can write an onject of the given source type to. The returned type might be a subclass - * oth the given expected type though. If {@code expectedTargetType} is {@literal null} we will simply return the - * first target type matching or {@literal null} if no conversion can be found. + * Returns the target type we can write an inject of the given source type to. The returned type might be a subclass + * of the given expected type though. If {@code expectedTargetType} is {@literal null} we will simply return the first + * target type matching or {@literal null} if no conversion can be found. * * @param sourceType must not be {@literal null} * @param requestedTargetType diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java index 47fa41776..8dfa262f5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java @@ -647,7 +647,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App Object val = entry.getValue(); if (conversions.isSimpleType(key.getClass())) { - String simpleKey = potentiallyConvertMapKey(key); + String simpleKey = potentiallyEscapeMapKey(potentiallyConvertMapKey(key)); if (val == null || conversions.isSimpleType(val.getClass())) { writeSimpleInternal(val, dbo, simpleKey); } else if (val instanceof Collection || val.getClass().isArray()) { @@ -670,16 +670,15 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App private String potentiallyConvertMapKey(Object key) { - String stringKey = null; - if (key instanceof String - || !(conversions.hasCustomWriteTarget(key.getClass()) && conversions.getCustomWriteTarget(key.getClass()) - .equals(String.class))) { - stringKey = key.toString(); - } else { - stringKey = (String) getPotentiallyConvertedSimpleWrite(key); + if (key instanceof String) { + return (String) key; } - return potentiallyEscapeMapKey(stringKey); + if (conversions.hasCustomWriteTarget(key.getClass(), String.class)) { + return (String) getPotentiallyConvertedSimpleWrite(key); + } + + return key.toString(); } /**