mapstruct / mapstruct/mapstruct-idea

Unexpected warning: ''.'' should not be used as a source

Open
#257 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
168
Forks
41
PR merge metrics
No merged PRs in 30d

Description

I often have a use-case when "." is a valid and correct source of my mapping. It is officially supported mapping source, so why the plugin reports it as "should not be used"? Is there any particular reason or maybe it is just a historical burden from the times when MapStruct actually didn't support "." as a source?

Example:

record Failure(String code, String detail) {}

class Foo {
  Failure failure;
}

class FooDto {
  String failureCode;
  String failureDetail;
}

public abstract class FooMapper {

  @Mapping(target = "failure", source = ".")
  public abstract Foo fromDto(FooDto fooDto);

  protected Failure mapFailure(FooDto fooDto) {
    return new Failure(fooDto.getFailureCode(), fooDto.getFailureDetail());
  }

}

Of course, in this particular case we can just use:

@Mapping(target = "failure.code", source = "failureCode")
@Mapping(target = "failure.detail", source = "failureDetail")

But there are more complex cases when the target object should be created manually, by a custom code, and the only possible source is the whole source object.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the warning with the FooMapper example and inspect how the MapStruct IntelliJ plugin handles @Mapping values whose source is ".". Compare that behavior with MapStruct's documented support for the source form; done means the valid mapping is no longer incorrectly warned about, or the reason for the warning is clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.