Skip to content

Commit a5e2093

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 bcb5628 commit a5e2093

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
@@ -1329,9 +1329,9 @@ protected String mapPropertyName(MongoPersistentProperty property) {
13291329

13301330
String partial = iterator.next();
13311331

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

1334-
if (isPositional) {
1334+
if (isPositional || property.isMap()) {
13351335
mappedName.append(".").append(partial);
13361336
}
13371337

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

+21
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,27 @@ void mappingShouldConsiderNestedPrefixedEmbeddedType() {
11591159
new Document("prefix-stringValue", "updated").append("prefix-listValue", Arrays.asList("val-1", "val-2")))));
11601160
}
11611161

1162+
@Test // GH-3552
1163+
void numericKeyForMap() {
1164+
1165+
Update update = new Update().set("map.601218778970110001827396", "testing");
1166+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1167+
context.getPersistentEntity(EntityWithObjectMap.class));
1168+
1169+
assertThat(mappedUpdate).isEqualTo(Document.parse("{\"$set\": {\"map.601218778970110001827396\": \"testing\"}}"));
1170+
}
1171+
1172+
@Test // GH-3552
1173+
void numericKeyInMapOfNestedPath() {
1174+
1175+
Update update = new Update().set("map.601218778970110001827396.value", "testing");
1176+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1177+
context.getPersistentEntity(EntityWithObjectMap.class));
1178+
1179+
assertThat(mappedUpdate)
1180+
.isEqualTo(Document.parse("{\"$set\": {\"map.601218778970110001827396.value\": \"testing\"}}"));
1181+
}
1182+
11621183
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
11631184
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
11641185
}

0 commit comments

Comments
 (0)