GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve Lombok integration documentation · Issue #3374 · mapstruct/mapstruct

Improve Lombok integration documentation #3374

New issue
Copy link
New issue
Copy link
Closed
Closed
Improve Lombok integration documentation#3374
Copy link
Labels
documentation
Milestone
1.6.0.Beta1

Description

@nikolas-charalambidis
nikolas-charalambidis
opened on Sep 7, 2023
Issue body actions

Expected behavior

Assuming the following code and configuration below, I expect the compilation to succeed and the mapper to generate something like this:

public Foo.CarDto toDto(Foo.Car car) {
    if (car == null) {
        return null;
    } else {
        Foo.CarDto carDto = new Foo.CarDto();
        carDto.setEWhatever2(car.getEWhatever1());
        return carDto;
    }
}

Actual behavior

Compilation fails and no implementation is generated.

java: No property named "eWhatever1" exists in source parameter(s). Did you mean "EWhatever1"?

Steps to reproduce the problem

  • Java 17
  • MapStruct 1.5.3.Final
  • Lombok 1.18.22
  • Lombok Mapstruct Binding 0.2.0
@Mapper
public interface BadMapper {

    @Mapping(target = "eWhatever2", source = "eWhatever1")
    CarDto toDto(Car car);
}
@Data
public class Car {

    private String eWhatever1;
}
@Data
public class CarDto {

    private String eWhatever2;
}

It is important the 1st letter of the variable is lowercase and the 2nd one is uppercase.

  • Ewhatever interestingly produces a similar error.
  • eWhatever doesn't work.
  • ewHatever is ok.
  • ewhatever is ok.

MapStruct Version

MapStruct 1.5.3.Final

Activity

  1. nikolas-charalambidis
    added
    bug
    on Sep 7, 2023
  2. filiphr commented on Sep 16, 2023

    @filiphr
    filiphr
    on Sep 16, 2023
    Member
    More actions

    This works as designed. MapStruct is using the Java Bean convention. This means that we are using getters / setters to determine the names of the properties. In this example the getter is getEWhatever the name of the property is EWhatever. The reason for this is due to the fact the first character after the get is lowercased if and only if the letter after that is lowercase.

  3. filiphr
    added
    not a bug
    and removed
    bug
    on Sep 16, 2023
  4. thunderhook commented on Sep 16, 2023

    @thunderhook
    thunderhook
    on Sep 16, 2023
    Contributor
    More actions

    You can however tell Lombok to generate getters using the Java Bean convention by providing a lombok.config file with the property: lombok.accessors.capitalization=beanspec

    For more info see https://projectlombok.org/features/GetterSetter

    Reacted by Nikolas Charalambidis
  5. nikolas-charalambidis commented on Sep 16, 2023

    @nikolas-charalambidis
    nikolas-charalambidis
    on Sep 16, 2023
    ContributorAuthor
    More actions

    @thunderhook A spot on! lombok.accessors.capitalization=beanspec resolves the whole issue. Many thanks!

    @filiphr I believe such a gotcha should be documented in the Mapstruct reference guide: https://mapstruct.org/documentation/stable/reference/html/#lombok I have created a PR (#3389), kindly, take a look.

    Reacted by Oliver E.
  6. filiphr
    added a commit that references this issue on Sep 17, 2023

    #3374 Lombok compatibility documentation

    032ee4d
  7. filiphr
    changed the title [-]Mapping cannot identify getter with Lombok on properties with the 2nd uppercase letter[/-] [+]Improve Lombok integration documentation[/+] on Sep 17, 2023
  8. filiphr
    added
    documentation
    and removed
    not a bug
    on Sep 17, 2023
  9. filiphr
    added this to the 1.6.0 milestone on Sep 17, 2023
  10. filiphr commented on Sep 17, 2023

    @filiphr
    filiphr
    on Sep 17, 2023
    Member
    More actions

    Thanks a lot for the documentation PR @nikolas-charalambidis. I merged it.

    Reacted by Nikolas Charalambidis
  11. filiphr
    closed this as completedon Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      • 1.6.0.Beta1

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.