spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Update Mapper test failed with object nested integer field #4502

Open juzq opened 1 year ago

juzq commented 1 year ago

when add following test code in UpdateMapperUnitTests.java, test would fail for parameter "levelOne.levelTwo.1.0" and "levelOne.levelTwo.2.0".

@ParameterizedTest
@ValueSource(strings = {"levelOne.levelTwo.1", "levelOne.levelTwo.1.0", "levelOne.levelTwo.2.0"})
void objectNestedIntegerFieldCorrectly(String path) {

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

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

static class EntityWithNestedObject1 {
    EntityWithNestedObject2 levelOne;
}

static class EntityWithNestedObject2 {
    Integer levelTwo;
}

test result:

expected: {"$set"={"levelOne.levelTwo.1.0"="4"}}
 but was: {"$set"={"levelOne.levelTwo.1"="4"}}

expected: {"$set"={"levelOne.levelTwo.2.0"="4"}}
 but was: {"$set"={"levelOne.levelTwo.2"="4"}}

yes, the last ".0" was lost, but parameter "levelOne.levelTwo.1" will test success.

the test code was pushed to my repository: https://github.com/juzq/spring-data-mongodb

christophstrobl commented 1 year ago

@juzq thanks for reporting and the test - we're working on a solution.

juzq commented 11 months ago

@mp911de need to merge #4514 to fix this issue.