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

Impossible to have an interface as inBean #119

Closed
loutente opened this issue Sep 28, 2016 · 0 comments
Closed

Impossible to have an interface as inBean #119

loutente opened this issue Sep 28, 2016 · 0 comments
Milestone

Comments

@loutente
Copy link

I cannot map an interface to a DTO
The interface describing my beans

public interface Person {
  String getNom();
  String getPrenom();
}

The implementation of my interface

public class PersonImpl implements Person {
  private String nom;
  private String prenom;
  public PersonImpl() {
  }
  public PersonImpl(String nom, String prenom) {
    this.nom = nom;
    this.prenom = prenom;
  }
  public String getNom() {
    return this.nom;
  }
  public String getPrenom() {
    return this.prenom;
  }
}

The Dto Bean

public class PersonDto {
  private String nom;
  private String prenom;
  public PersonDto() {
  }
  public void setNom(String nom) {
    this.nom = nom;
  }
  public void setPrenom(String prenom) {
    this.prenom = prenom;
  }
  public String getNom() {
    return this.nom;
  }
  public String getPrenom() {
    return this.prenom;
  }
}

The mapper

@Mapper
public interface PersonMapper {
  PersonDto toDto(Person patient);
}

The Unit test fails

public class PersonMapperTest {
  public static final String NOM = "nom";
  public static final String PRENOM = "prenom";
  private PersonMapper personMapper = Selma.builder(PersonMapper.class).build();

  @Test
  public void shouldMap() {
    Person person = new PersonImpl(NOM, PRENOM);
    PersonDto personDto = personMapper.toDto(person);
    assertThat(personDto.getNom()).isEqualTo(NOM);
    assertThat(personDto.getPrenom()).isEqualTo(PRENOM);
  }
}

The impacted selma code is the isGetter method of MethodWrapper class.
If you remove the test on Modifier.ABSTRACT all works fine.

public class MethodWrapper {
...
    public boolean isGetter() {
        boolean res = false;
        if (hasNoParameter() && method.getReturnType().getKind() != TypeKind.VOID
                && method.getModifiers().contains(Modifier.PUBLIC)
                && !method.getModifiers().contains(Modifier.ABSTRACT)
                && !method.getModifiers().contains(Modifier.STATIC)) {
            Matcher getterMatcher = GETTER_PATTERN.matcher(method.getSimpleName());
            res = getterMatcher.matches();
            if (res) {
                fieldName = getterMatcher.group(2);
            }
        }
        return res;
    }
}

We were confronted to this problem using spring data mongoDb projections mapping to rest dto beans.

demo.zip

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

No branches or pull requests

2 participants