publicissapient-france/selma

Mapping from an object with type parameters and custom fields generates bad code

binarymelon opened this issue · 1 comments

Given the following objects

Bar.java

public class Bar
{
	private Long id;
	private String description;

	public Long getId()
	{
		return id;
	}

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

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}
}

Foo.java

public class Foo<E>
{
	private E item;

	public E getItem()
	{
		return item;
	}

	public void setItem(E item)
	{
		this.item = item;
	}
}

This mapper generates bad code.

FooMapper.java

@Mapper(withCustomFields = {
		@Field({"id", "item.id"}),
		@Field({"description", "item.description"})
})
interface FooMapper
{
	Foo<Bar> asFoo(Bar bar);
	Bar asBar(Foo<Bar> foo);
}

asFoo generates correctly, but asBar generates the following code

@Override
  public final Bar asBar(Foo<Bar> inBar) {
    Bar out = null;
    if (inBar != null) {
      out = new Bar();
      if (inFoo<E.getItem() != null) {
        out.setDescription(inFoo<E.getItem().getDescription());
      }
      if (inFoo<E.getItem() != null) {
        out.setId(inFoo<E.getItem().getId());
      }
    }
    return out;
  }

Hi Thanks for reporting,

the bug is now fixed in snapshot.