Skip to content

Commit c3b4f61

Browse files
christophstroblmp911de
authored andcommitted
Preserve class keyword as Map key during update mapping.
This commit makes sure to skip the class property ob Object when mapping maps and their keys inside an Update. Closes #3566 Original pull request: #3577.
1 parent 22ed860 commit c3b4f61

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,8 @@ private PropertyPath forName(String path) {
11521152

11531153
private boolean isPathToJavaLangClassProperty(PropertyPath path) {
11541154

1155-
if (path.getType().equals(Class.class) && path.getLeafProperty().getOwningType().getType().equals(Class.class)) {
1155+
if ((path.getType() == Class.class || path.getType().equals(Object.class))
1156+
&& path.getLeafProperty().getType() == Class.class) {
11561157
return true;
11571158
}
11581159
return false;

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

+11
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,17 @@ void numericKeyInMapOfNestedPath() {
11101110
.isEqualTo("{\"$set\": {\"map.601218778970110001827396.value\": \"testing\"}}");
11111111
}
11121112

1113+
@Test // GH-3566
1114+
void mapsObjectClassPropertyFieldInMapValueTypeAsKey() {
1115+
1116+
Update update = new Update().set("map.class", "value");
1117+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1118+
context.getPersistentEntity(EntityWithObjectMap.class));
1119+
1120+
assertThat(mappedUpdate)
1121+
.isEqualTo("{\"$set\": {\"map.class\": \"value\"}}");
1122+
}
1123+
11131124
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
11141125
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
11151126
}

0 commit comments

Comments
 (0)