Skip to content

Commit 859a0e8

Browse files
committed
DATAMONGO-1423 - Polishing.
Orignal pull request: #365.
1 parent b35f151 commit 859a0e8

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
@@ -993,21 +993,30 @@ public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation)
993993
}
994994

995995
if (obj instanceof DBObject) {
996+
996997
DBObject newValueDbo = new BasicDBObject();
998+
997999
for (String vk : ((DBObject) obj).keySet()) {
1000+
9981001
Object o = ((DBObject) obj).get(vk);
9991002
newValueDbo.put(vk, convertToMongoType(o, typeHint));
10001003
}
1004+
10011005
return newValueDbo;
10021006
}
10031007

10041008
if (obj instanceof Map) {
1009+
10051010
Map<Object, Object> converted = new LinkedHashMap<Object, Object>();
10061011

1007-
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) obj).entrySet()) {
1008-
converted.put(convertToMongoType(entry.getKey()), convertToMongoType(entry.getValue(),
1009-
typeHint != null && typeHint.getMapValueType() != null ? typeHint.getMapValueType() : typeHint));
1012+
for (Entry<Object, Object> entry : ((Map<Object, Object>) obj).entrySet()) {
1013+
1014+
TypeInformation<? extends Object> valueTypeHint = typeHint != null && typeHint.getMapValueType() != null
1015+
? typeHint.getMapValueType() : typeHint;
1016+
1017+
converted.put(convertToMongoType(entry.getKey()), convertToMongoType(entry.getValue(), valueTypeHint));
10101018
}
1019+
10111020
return new BasicDBObject(converted);
10121021
}
10131022

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
@@ -891,6 +891,7 @@ public void mapsAtomicIntegerToPrimitiveIntegerCorrectly() {
891891
* @see DATAMONGO-1423
892892
*/
893893
@Test
894+
@SuppressWarnings("unchecked")
894895
public void mappingShouldConsiderCustomConvertersForEnumMapKeys() {
895896

896897
CustomConversions conversions = new CustomConversions(

0 commit comments

Comments
 (0)