Skip to content

UpdateMapper drops numeric keys in Maps #3552

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
RamThirupathy opened this issue Feb 12, 2021 · 2 comments
Closed

UpdateMapper drops numeric keys in Maps #3552

RamThirupathy opened this issue Feb 12, 2021 · 2 comments
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@RamThirupathy
Copy link

RamThirupathy commented Feb 12, 2021

Numeric Bson Ids are dropped when using findAndModify method in org.springframework.data.mongodb.core.MongoTemplate.

Ex:

public class Foo {
 private Map<String, String> map;
 
 private Map<String, String> getMap() {
   return map;
 }

 private void setMap(Map<String, String> map) {
   this.map = map
  }
}
@Test
public void test() {
    Foo foo = new Foo();
    mongoTemplate.save(foo);
    Update update = new Update().set("map.601218778970110001827396", "testing");
    druryIssue = mongoTemplate.findAndModify(new Query(Criteria.where("_id").is(foo.getId())), update,
          new FindAndModifyOptions().returnNew(true),  Foo.class);
    System.out.println(druryIssue.map);
}

Foo is saved us

{
    "_id" : ObjectId("6023ff93defc2460cc3c4a26"),
    "_class" : "com.test.Foo",
    "map" : "testing"//it should have been "map.601218778970110001827396":"testing"
}

and resulting in exception


org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<?, ?>]
	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:206)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getPotentiallyConvertedSimpleRead(MappingMongoConverter.java:838)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1230)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:84)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1176)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:886)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:290)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:278)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:331)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:278)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:238)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:198)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:194)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:84)
	at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2306)
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1907)
	at org.springframework.data.mongodb.core.MongoTemplate.doFindAndModify(MongoTemplate.java:1839)
	at org.springframework.data.mongodb.core.MongoTemplate.findAndModify(MongoTemplate.java:715)
	at org.springframework.data.mongodb.core.MongoTemplate.findAndModify(MongoTemplate.java:710)

Note: This is working when we directly using Java Mongo driver instead of spring-data-mongodb.
spring-data-mongodb version is: 1.10.18.RELEASE

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 12, 2021
@christophstrobl christophstrobl self-assigned this Feb 19, 2021
@christophstrobl
Copy link
Member

Thanks for reporting. We'll look into this.

@christophstrobl christophstrobl added type: bug A general bug in: mapping Mapping and conversion infrastructure and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 19, 2021
@mp911de
Copy link
Member

mp911de commented Feb 22, 2021

Note that the 1.x line of Spring Data MongoDB is out of maintenance since late 2019.

mp911de pushed a commit that referenced this issue Feb 22, 2021
This commit makes sure we preserve map keys no matter what.

Closes #3552.
Original pull request: #3565.
mp911de added a commit that referenced this issue Feb 22, 2021
Simplify assertions.

See #3552.
Original pull request: #3565.
mp911de pushed a commit that referenced this issue Feb 22, 2021
This commit makes sure we preserve map keys no matter what.

Closes #3552.
Original pull request: #3565.
mp911de added a commit that referenced this issue Feb 22, 2021
Simplify assertions.

See #3552.
Original pull request: #3565.
mp911de added a commit that referenced this issue Feb 22, 2021
Simplify assertions.

See #3552.
Original pull request: #3565.
@mp911de mp911de added this to the 3.0.8 (Neumann SR8) milestone Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
4 participants