spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Update Mapper test failed with object nested integer field

Open juzq opened this issue 2 years ago • 2 comments

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

juzq avatar Sep 13 '23 10:09 juzq

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

christophstrobl avatar Sep 26 '23 13:09 christophstrobl

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

juzq avatar Nov 23 '23 06:11 juzq