2021-05-01 15:12:14 +02:00
2023-07-28 00:10:07 +02:00
2023-08-26 13:24:38 +02:00
2021-05-01 12:06:40 +00:00
2025-12-06 12:53:37 +01:00
2023-08-26 13:25:53 +02:00

mapstruct-support

Additional DefaultAccessorNamingStrategy to support fluent API withXYZ setters.

License

What is MapStruct?

MapStruct is a Java annotation processor for the generation of type-safe and performant mappers for Java bean classes.

To learn more about MapStruct have a look at the mapstruct repository or the website

Features

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.

Usage

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.5.5.Final</version>
  </dependency>
  <dependency>
    <groupId>de.muehlencord.mapstruct</groupId>
    <artifactId>mapstruct-support</artifactId>
    <version>1.5.5</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 a 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;
  }
}

Requirements

The MapStruct plugin requires Java 11 or later

Building from Source

mapstruct-support uses maven as build system. Simple execute

 mvn clean install

Licensing

The MapStruct plugin is licensed under the Apache License, Version 2.0 (the "License"); you may not use it except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.

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