Skip to content

Commit 9b04dd8

Browse files
odrotbohmchristophstrobl
authored andcommitted
DATAMONGO-1423 - Polishing.
Orignal pull request: #365.
1 parent 8c66269 commit 9b04dd8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,22 +1089,31 @@ public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation)
10891089
}
10901090

10911091
if (obj instanceof DBObject) {
1092+
10921093
Document newValueDbo = new Document();
1094+
10931095
for (String vk : ((DBObject) obj).keySet()) {
1096+
10941097
Object o = ((DBObject) obj).get(vk);
10951098
newValueDbo.put(vk, convertToMongoType(o, typeHint));
10961099
}
1100+
10971101
return newValueDbo;
10981102
}
10991103

11001104
if (obj instanceof Map) {
11011105

11021106
Map<String, Object> converted = new LinkedHashMap<String, Object>();
11031107

1104-
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) obj).entrySet()) {
1105-
converted.put(convertToMongoType(entry.getKey()).toString(), convertToMongoType(entry.getValue(),
1106-
typeHint != null && typeHint.getMapValueType() != null ? typeHint.getMapValueType() : typeHint));
1108+
for (Entry<Object, Object> entry : ((Map<Object, Object>) obj).entrySet()) {
1109+
1110+
TypeInformation<? extends Object> valueTypeHint = typeHint != null && typeHint.getMapValueType() != null
1111+
? typeHint.getMapValueType() : typeHint;
1112+
1113+
converted.put(convertToMongoType(entry.getKey()).toString(),
1114+
convertToMongoType(entry.getValue(), valueTypeHint));
11071115
}
1116+
11081117
return new Document(converted);
11091118
}
11101119

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ public void mapsMaxCorrectly() {
911911
* @see DATAMONGO-1423
912912
*/
913913
@Test
914+
@SuppressWarnings("unchecked")
914915
public void mappingShouldConsiderCustomConvertersForEnumMapKeys() {
915916

916917
CustomConversions conversions = new CustomConversions(

0 commit comments

Comments
 (0)