2022-06-12 00:25:57 +02:00
2021-05-01 15:12:14 +02:00
2021-05-01 15:12:14 +02:00
2021-05-01 12:06:40 +00:00
2022-06-12 00:25:57 +02:00
2021-05-01 15:16:21 +02:00

mapstruct-support

Additional DefaultAccessorNamingStrategy to support fluent API withXYZ setters.

Mapstruct default naming strategy detects the methods withFirstName and withLastName (see example below) as extra target fields and therefore cause an error, when the mapper is annotated with unmappedTargetPolicy = ReportingPolicy.ERROR.

The additional naming strategy makes Mapstruct ignore the withXYZ setters.

Installation

To use the extended naming strategy, just include it as project dependency alongside with mapstruct.


<dependencies>
  <dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct</artifactId>
    <version>1.4.2.Final</version>
  </dependency>
  <dependency>
    <groupId>de.muehlencord.mapstruct</groupId>
    <artifactId>mapstruct-support</artifactId>
    <version>1.4.2</version>
  </dependency>
</dependencies>

Example

public class Person {

  private String firstName;
  private String lastName;

  // standard getter / setter - these are covered by mapstruct by default */
  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  /* fluent setter - these are detected as extra setters and would
     cause an mapping exception, if the mapper is annotated with 
     unmappedTargetPolicy = ReportingPolicy.ERROR. 
   */

  public Person withFirstName(String firstName) {
    this.firstName = firstName;
    return this;
  }

  public Person withLastName(String lastName) {
    this.lastName = lastName;
    return this;
  }
}

Description
Additional DefaultAccessorNamingStrategy to support fluent API withXYZ setters.
Readme 60 KiB
2024-12-26 21:04:52 +00:00
Languages
Java 100%