Skip to content
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

Selma Mapper not working between List<ClassA> & List<ClassB> (Java, maven) #207

Open
krabouilleur opened this issue Sep 13, 2019 · 0 comments

Comments

@krabouilleur
Copy link

krabouilleur commented Sep 13, 2019

I've the class "ArticleEntity", "CategoryEntity" and "Article".
I've the ArticleEntity:

public class ArticleEntity {
 ...
 @ManyToOne
 @JoinColumn
 private CategoryEntity categoryEntity;

 public CategoryEntity getCategoryEntity() {
	return categoryEntity;
 }

 public void setCategoryEntity(CategoryEntity categoryEntity) {
	this.categoryEntity = categoryEntity;
 }
}

And a class B

public class CategoryEntity {
 ...
 private String name;
 ...getter & setter

 @OneToMany(mappedBy = "categoryEntity")
 private List<ArticleEntity> articles;

 public List<ArticleEntity> getArticles() {
	if(articles == null) {
		articles = new ArrayList<>();
	}
	return articles;
 }

 public void setArticles(List<ArticleEntity> articles) {
	this.articles = articles;
 }
}

And a model class:

public class Article {
 ...
 private String categoryName;

 public String getCategoryName() {
	return categoryName;
 }

 public void setCategoryName(String categoryName) {
	this.categoryName = categoryName;
 }
}

With Selma, I make this mapper:

@Mapper(withIgnoreMissing = IgnoreMissing.ALL, withIoC = IoC.SPRING) 
public interface ArticleMapper {
  ...
  @Maps(withCustomFields = {
   @Field({"categoryEntity.name", "categoryName"})
  })
  List<Article> articlesFromArticleEntity(List<ArticleEntity> articlesEntity);
}

The result of "List Article" mapping is for example:

[0]-> 
CategoryName: null
Content: "Hello here my content"
title: "My title here !"

Why mapping list with List doesn't work (CategoryName is null) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant