Skip to content

Fix QueryMapper deal map nested last big integer bug #4427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,18 @@ private PersistentPropertyPath<MongoPersistentProperty> getPath(String pathExpre

String rawPath = removePlaceholders(POSITIONAL_OPERATOR,
removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression));
// fix xx.11.22.33 becomes xx3, it should be xx.33, then path should be null. (test mapNestedLastBigIntegerFieldCorrectly)
if (pathExpression.contains(".")) {
String lastDotString = pathExpression.substring(pathExpression.lastIndexOf("."));
int lastDotLength = lastDotString.length();
int newLength = 0;
if (rawPath.contains(".")) {
newLength = rawPath.substring(rawPath.lastIndexOf(".")).length();
}
if (lastDotLength != newLength) {
rawPath = rawPath.substring(0, rawPath.length() - 1) + lastDotString;
}
}

if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
return mappingContext.getPersistentPropertyPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,16 @@ void mapNestedIntegerFieldCorrectly() {
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.3", "4")));
}

@Test
void mapNestedLastBigIntegerFieldCorrectly() {

Update update = new Update().set("levelOne.0.1.32", "4");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));

assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.32", "4")));
}

@Test // GH-3775
void mapNestedMixedStringIntegerFieldCorrectly() {

Expand Down Expand Up @@ -1732,6 +1742,8 @@ static class UnwrappableType {

static class EntityWithNestedMap {
Map<String, Map<String, Map<String, Object>>> levelOne;
// for test mapNestedLastBigIntegerFieldCorrectly()
Map<String, Map<String, Map<String, Object>>> levelOne2;
}

static class Customer {
Expand Down