Skip to content

Projecting nested documents with open projections leads to ConverterNotFoundException #3998

Closed
@mp911de

Description

@mp911de

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;
		}
	}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions