Skip to content

Commit 52b13cc

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 d73c2e3 commit 52b13cc

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
@@ -1220,7 +1220,8 @@ private PropertyPath forName(String path) {
12201220

12211221
private boolean isPathToJavaLangClassProperty(PropertyPath path) {
12221222

1223-
if (path.getType().equals(Class.class) && path.getLeafProperty().getOwningType().getType().equals(Class.class)) {
1223+
if ((path.getType() == Class.class || path.getType().equals(Object.class))
1224+
&& path.getLeafProperty().getType() == Class.class) {
12241225
return true;
12251226
}
12261227
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
@@ -1180,6 +1180,17 @@ void numericKeyInMapOfNestedPath() {
11801180
.isEqualTo("{\"$set\": {\"map.601218778970110001827396.value\": \"testing\"}}");
11811181
}
11821182

1183+
@Test // GH-3566
1184+
void mapsObjectClassPropertyFieldInMapValueTypeAsKey() {
1185+
1186+
Update update = new Update().set("map.class", "value");
1187+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1188+
context.getPersistentEntity(EntityWithObjectMap.class));
1189+
1190+
assertThat(mappedUpdate)
1191+
.isEqualTo("{\"$set\": {\"map.class\": \"value\"}}");
1192+
}
1193+
11831194
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
11841195
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
11851196
}

0 commit comments

Comments
 (0)