Skip to content

Commit c20feab

Browse files
christophstroblmp911de
authored andcommitted
Preserve numeric keys that exceed Long range when mapping Updates.
This commit makes sure we preserve map keys no matter what. Closes #3552. Original pull request: #3565.
1 parent f93e40f commit c20feab

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,9 @@ protected String mapPropertyName(MongoPersistentProperty property) {
12611261

12621262
String partial = iterator.next();
12631263

1264-
boolean isPositional = (isPositionalParameter(partial) && (property.isMap() || property.isCollectionLike()));
1264+
boolean isPositional = isPositionalParameter(partial) && property.isCollectionLike();
12651265

1266-
if (isPositional) {
1266+
if (isPositional || property.isMap()) {
12671267
mappedName.append(".").append(partial);
12681268
}
12691269

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

+21
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,27 @@ void mappingShouldAllowNestedPositionParameterWithIdentifierWhenFieldHasExplicit
10891089
assertThat(mappedUpdate).isEqualTo(new Document("$set", new Document("aliased.$[element].value", 10)));
10901090
}
10911091

1092+
@Test // GH-3552
1093+
void numericKeyForMap() {
1094+
1095+
Update update = new Update().set("map.601218778970110001827396", "testing");
1096+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1097+
context.getPersistentEntity(EntityWithObjectMap.class));
1098+
1099+
assertThat(mappedUpdate).isEqualTo(Document.parse("{\"$set\": {\"map.601218778970110001827396\": \"testing\"}}"));
1100+
}
1101+
1102+
@Test // GH-3552
1103+
void numericKeyInMapOfNestedPath() {
1104+
1105+
Update update = new Update().set("map.601218778970110001827396.value", "testing");
1106+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1107+
context.getPersistentEntity(EntityWithObjectMap.class));
1108+
1109+
assertThat(mappedUpdate)
1110+
.isEqualTo(Document.parse("{\"$set\": {\"map.601218778970110001827396.value\": \"testing\"}}"));
1111+
}
1112+
10921113
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
10931114
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
10941115
}

0 commit comments

Comments
 (0)