0

I have the following mapstruct interface:

@Mapper
public interface CustomerMapper
{
  CustomerMapper INSTANCE = Mappers.getMapper(CustomerMapper.class);
  public Customer fromEntity(CustomerEntity customerEntity);
  @InheritInverseConfiguration
  CustomerEntity fromCustomer (Customer customer);
}

and here is the generated class:

public class CustomerMapperImpl implements CustomerMapper {
  public CustomerMapperImpl() {
  }

  public Customer fromEntity(CustomerEntity customerEntity) {
    if (customerEntity == null) {
      return null;
    } else {
      Customer customer = new Customer();
      return customer;
    }
  }

  public CustomerEntity fromCustomer(Customer customer) {
    if (customer == null) {
      return null;
    } else {
      CustomerEntity customerEntity = new CustomerEntity();
      return customerEntity;
    }
  }
}

Where are the setters ? The generated class is supposed to call the setters and to initialize properties, for example:

...
Customer customer = new Customer();
customer.setXXX(customerEntity.getXXX());
...

Here is the maven compile plugin configuration:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <source>11</source>
      <target>11</target>
      <annotationProcessorPaths>
        <path>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct-processor</artifactId>
          <version>${mapstruct.version}</version>
        </path>
        <path>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>${lombock.version}</version>
        </path>
      </annotationProcessorPaths>
    </configuration>
  </plugin>

Did I miss anything here ?

Many thanks in advance.

Seymour

Seymour Glass
  • 81
  • 2
  • 15
  • I am 99% sure that this is linked to Lombok. See https://stackoverflow.com/questions/47676369/mapstruct-and-lombok-not-working-together/47684351#47684351 – Filip Feb 11 '21 at 11:24
  • I have updated the case to show the maven compile plugin configuration. However, the mapper is not generated as expected. – Seymour Glass Feb 11 '21 at 16:47
  • My bad, I didn't observe the right path order: lombok has to come first and then mapstruct. Thanks @Filip for pointing me to the solution. By the way, in my case lombok-mapstruct-binding doesn't seem to be required. – Seymour Glass Feb 11 '21 at 16:53
  • @Filip: please provide your solution as an answer such that I can accept it. – Seymour Glass Feb 11 '21 at 16:55
  • Does this answer your question? [MapStruct and Lombok not working together](https://stackoverflow.com/questions/47676369/mapstruct-and-lombok-not-working-together) – Filip Feb 12 '21 at 12:12
  • Yes, it does, as confirmed above. – Seymour Glass Feb 12 '21 at 18:40

0 Answers0