Skip to content

Getting exception in MappingMongoConverter while trying to map array of string into string #4371

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
packageman opened this issue Apr 24, 2023 · 3 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@packageman
Copy link

When I upgrade spring-data-mongodb from 3.1.8 to 3.3.5, I encountered below exception:

org.springframework.data.mapping.MappingException: Cannot convert [a, b, c] of type class java.util.ArrayList into an instance of class java.lang.String! Implement a custom Converter<class java.util.ArrayList, class java.lang.String> and register it with the CustomConversions. Parent object was: MemberGroup(id=6271f70e87d74d524481a418, accountId=5b036b566e2bdaa2074b0101, proposedGroupId=null, name=byron-test-9, description=Byron Test 18, type=portal, conditionGroups=[MemberGroup.MemberGroupConditionGroup(name=null, conjunction=OR, conditions=[MemberGroup.MemberGroupCondition(type=EVENT, filters=[Filter(type=STRING, field=properties.channelId, operator=IN, value=[5ad411ab6f82dc001f2420f0], caseSensitive=null, aggregation=null, expression=null, isEditable=null, editableFields=null, extra=null, fieldForSql=null), Filter(type=STRING, field=name, operator=EQUALS, value=maievent-subscribe, caseSensitive=false, aggregation=null, expression=null, isEditable=null, editableFields=null, extra=null, fieldForSql=null)])], isEditable=null, editableFields=null)], memberCount=7, computingAt=null, computedAt=2022-05-27T20:44:04.858, editedAt=null, isEnabled=true, dontCompute=false, inDeveloperMode=false, isDeleted=false, dataSource=null, distributorId=null, distributorIds=null, createdBy=null, events=null) -> null
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$ConversionContext.convert(MappingMongoConverter.java:2044)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1779)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:512)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.populateProperties(MappingMongoConverter.java:425)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:394)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readDocument(MappingMongoConverter.java:356)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:292)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:288)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:107)
	at org.springframework.data.mongodb.core.MongoTemplate$ReadDocumentCallback.doWith(MongoTemplate.java:3207)
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:2822)
	at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:2529)
	at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:811)
	at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:798)
	at com.xxx.bigdata.repository.BaseRepository.getOneById(BaseRepository.java:102)
	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)

Checked MappingMongoConverter.java commit history, I found out that this commit caused the above exception. It seems that this commit is just doing refactoring, not to change the program execution behavior.

So is the above exception an intentional change or a bug caused by refactoring?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 24, 2023
@christophstrobl
Copy link
Member

It is hard to tell what actually causes the problem by just looking at the exception message without the context the conversion is running in. Please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Apr 24, 2023
@christophstrobl christophstrobl self-assigned this Apr 24, 2023
@christophstrobl christophstrobl removed the status: waiting-for-triage An issue we've not yet triaged label Apr 24, 2023
@packageman
Copy link
Author

I wrote a demo application, you may need:

  • update mongo uri accordingly in config/MongoConfig.java.
  • insert test data (db.user.insert({"_id" : ObjectId("644755d3e3e11b27f1997ff5"), "name" : "test", "age" : 20, "favorites" : ["swimming", "football"]})) in mongodb.
  • run ./mvnw spring-boot:run
  • run curl localhost:8080/test to see the result (it will succeed because currently the app is running with spring-data-mongodb-3.1.8).
  • add spring-data-mongodb-3.3.5 dependency in pom.xml to make the newer version take effect and test again, you will see an exception occurs.

spring-mongodb-test.tar.gz

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 25, 2023
@christophstrobl
Copy link
Member

@packageman thanks for the reproducer.

@mp911de mp911de added type: regression A regression from a previous release and removed status: feedback-provided Feedback has been provided labels May 10, 2023
mp911de pushed a commit that referenced this issue May 10, 2023
Previous versions allow arbitrary values to be mapped to an string property by calling the ObjectToString converter. This behaviour got lost and is not reestablished.

Closes #4371
Original pull request #4373
mp911de pushed a commit that referenced this issue May 10, 2023
Previous versions allow arbitrary values to be mapped to an string property by calling the ObjectToString converter. This behaviour got lost and is not reestablished.

Closes #4371
Original pull request #4373
@mp911de mp911de added this to the 3.4.12 (2021.2.12) milestone May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants