Skip to content

Projecting nested documents with open projections leads to ConverterNotFoundException #3998

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
mp911de opened this issue Mar 16, 2022 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@mp911de
Copy link
Member

mp911de commented Mar 16, 2022

Exception:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.mongodb.core.convert.$Proxy54] to type [org.springframework.data.mongodb.core.convert.MappingMongoConverterUnitTests$Author]

	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)
	at org.springframework.data.mapping.model.ConvertingPropertyAccessor.convertIfNecessary(ConvertingPropertyAccessor.java:121)
	at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:64)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$PropertyTranslatingPropertyAccessor.setProperty(MappingMongoConverter.java:2331)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:678)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.doReadProjection(MappingMongoConverter.java:339)
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.project(MappingMongoConverter.java:314)

Domain model:

	interface BookProjection {

		@Value("#{target.name + ' by ' + target.author.firstName + ' ' + target.author.lastName}")
		String getName();
	}

	static class Book {

		@Id String id;

		String name;

		Author author = new Author();

		public Book() {}

		public Book(String id, String name, Author author) {
			this.id = id;
			this.name = name;
			this.author = author;
		}

		public String getId() {
			return this.id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getName() {
			return this.name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public Author getAuthor() {
			return this.author;
		}

		public void setAuthor(Author author) {
			this.author = author;
		}

	}

	static class Author {

		@Id String id;

		String firstName;

		String lastName;

		public Author() {}

		public Author(String id, String firstName, String lastName) {
			this.id = id;
			this.firstName = firstName;
			this.lastName = lastName;
		}

		public String getId() {
			return this.id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getFirstName() {
			return this.firstName;
		}

		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}

		public String getLastName() {
			return this.lastName;
		}

		public void setLastName(String lastName) {
			this.lastName = lastName;
		}

		public String getFullName() {
			return this.firstName + " " + this.lastName;
		}
	}
@mp911de mp911de added the type: bug A general bug label Mar 16, 2022
@mp911de mp911de added this to the 3.4 M4 (2021.2.0) milestone Mar 16, 2022
@mp911de mp911de changed the title Reading open projections through MappingMongoConverter lead to ConverterNotFoundException Projecting nested documents with open projections leads to ConverterNotFoundException Mar 16, 2022
mp911de added a commit that referenced this issue Mar 16, 2022
We now create a new conversion context to ensure that we use the correct property type to avoid type retention when mapping complex objects within a projection.

Closes #3998
mp911de added a commit that referenced this issue Mar 16, 2022
Reformat code.

See #3998
@mp911de mp911de self-assigned this Mar 16, 2022
mp911de added a commit that referenced this issue Mar 16, 2022
Reformat code.

See #3998
mp911de added a commit that referenced this issue Mar 16, 2022
Reformat code.

See #3998
mp911de added a commit that referenced this issue Mar 16, 2022
Reformat code.

See #3998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant