Skip to content

DATAMONGO-2044 make ensureNotIterable actually check if object is iterable #590

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

Conversation

GotoFinal
Copy link
Contributor

@GotoFinal GotoFinal commented Aug 7, 2018

Other option would be just to remove that check, as it might be possible that someone is saving objects that implement iterable but are valid data classes?

As current code just does nothing, as object can be of type that is implementing one of that interfaces, but it can not be of interface type itself.

@GotoFinal
Copy link
Contributor Author

GotoFinal commented Aug 7, 2018

Now I'm confused as now I see there is a test that ensures that iterable item will pass here, so maybe this code should be just removed?

@Test // DATAMONGO-805
public void shouldMapFieldsOfIterableEntity() {
template.dropCollection(IterableItem.class);
template.dropCollection(Container.class);
Item item = new IterableItem();
item.value = "bar";
template.insert(item);
Container container = new Container("foo");
container.item = item;
template.insert(container);
Query query = new Query(Criteria.where("id").is("foo"));
Container result = template.findOne(query, Container.class);
assertThat(result, is(notNullValue()));
assertThat(result.item, is(notNullValue()));
assertThat(result.item.value, is("bar"));
}

But issues itself is not about iterable entities: https://jira.spring.io/browse/DATAMONGO-805

Other option would be to check if it is an array or collection - but then someone can implement collection in same way (as simple delegated wrapper) as in test mentioned above and that would be still valid data class? But I will change this commit to use collection for now and wait for some feedback.

@GotoFinal GotoFinal force-pushed the issue/DATAMONGO-2044 branch from 1a682a5 to 77895bd Compare August 7, 2018 11:01
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 4, 2021
christophstrobl pushed a commit that referenced this pull request Feb 22, 2021
Check if an object is an array or is an instance of collection or iterator instead of checking against collection names which is likely to never work.

Closes #2911
Original Pull Request: #590
christophstrobl added a commit that referenced this pull request Feb 22, 2021
…ntityOperations.

Reintroduce the protected ensureNotIterable method in MongoTemplate to keep the API stable. Delegate to the newly introduced method and move the collection like check to EntityOperations.

Original Pull Request: #590
@christophstrobl
Copy link
Member

thanks @GotoFinal. Sorry it took so long - merged to main line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ensureNotIterable in MongoTemplate only checks for array type [DATAMONGO-2044]
3 participants