Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Mappings suddenly stop with return null #3575

Closed
Zegveld opened this issue Apr 24, 2024 · 5 comments
Closed

Nested Mappings suddenly stop with return null #3575

Zegveld opened this issue Apr 24, 2024 · 5 comments
Assignees
Labels

Comments

@Zegveld
Copy link
Contributor

Zegveld commented Apr 24, 2024

Situation description

I'm using mapstruct to handle conversions from an older version of a datastructure to a newer version.
Example of changes that happen for me:
Old data structure:

A
- AA
- AB
  - ABA
    - ABAA
      - ABAAA
    - ABAB
    - ABAC
  - ABB
    - ABBA
    - ABBB
- AC

New data structure:

A
- AA
  - ABAA
    - ABAAA
  - ABBB
- AB
  - ABA
    - ABAB
  - ABB
    - ABBA
- AC
  - ABAC

Expected behavior

Now I've defined a single mapping tree to handle all the movements:

@Mapping(source = "AB.ABA.ABAA", target = "AA.ABAA")
@Mapping(source = "AB.ABA.ABAC", target = "AC.ABAC")
old.package.A mapA(new.package.A source);

Expected is that mapstruct continues with mapping of the code. In 1.5.5 this was also the case.

void abaaToAbaa(new.package.ABAA source, old.package.ABAA mappingTarget) {
  if (source == null) {
    return;
  }
  mappingTarget.setABAAA(source.getABAAA());
}

Actual behavior

This results in the following code being generated:

void abaaToAbaa(new.package.ABAA source, old.package.ABAA mappingTarget) {
  if (source == null) {
    return;
  }
}

Steps to reproduce the problem

To be added once reproduced in mapstruct code base itself.

MapStruct Version

Mapstruct 1.6.0.Beta1

@Zegveld Zegveld added the bug label Apr 24, 2024
@Zegveld Zegveld self-assigned this Apr 24, 2024
@Zegveld Zegveld added this to the 1.6.0.Beta2 milestone Apr 24, 2024
@Zegveld Zegveld changed the title Deep Mappings suddenly stop with return null Deep Nested Mappings suddenly stop with return null Apr 24, 2024
@Zegveld Zegveld changed the title Deep Nested Mappings suddenly stop with return null Nested Mappings suddenly stop with return null Apr 24, 2024
@Zegveld
Copy link
Contributor Author

Zegveld commented Apr 24, 2024

Running into problem that I'm not able to get it reproduceable within the mapstruct code-base IT's. Think I'll go debug the workings of mapstruct in the private codebase to figure out why it goes wrong, and then use this knowledge to create a reproduction scenario.

@Zegveld
Copy link
Contributor Author

Zegveld commented Apr 25, 2024

After some more analysis, the cause was a ignoreByDefault=true which was present on the top level bean mapping. This caused all the forged methods from that mapping to inherit it.

Closing this issue as invalid, but we might need to discuss how we want ignoreByDefault to behave....

@Zegveld Zegveld closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
@Zegveld Zegveld removed this from the 1.6.0.Beta2 milestone Apr 25, 2024
@Zegveld Zegveld added invalid and removed bug labels Apr 25, 2024
@alantanlc
Copy link

alantanlc commented May 13, 2024

@Zegveld I am facing a similar issue on 1.6.0.Beta1 where the deeply nested object fields are not being mapped. Possible to reopen this issue?

Situation

Mapping(source = "a.b.c.d1", target = "name")
D2 aToD2(A a);

Expected Behaviour

D2 d1ToD2(D1 d1) {
  if (d1 == null) {
    return;
  }
  
  D2 d2 = new D2();
  d2.setName( d1.getName() );

  return d2;
}

Actual Behaviour

D2 d1ToD2(D1 d1) {
  if (d1 == null) {
    return;
  }
  
  D2 d2 = new D2();
  // missing d2.setName( d1.getName() );

  return d2;
}

As a result, the target object is being created but with its fields not populated.

@thunderhook
Copy link
Contributor

@alantanlc Could you please provide a reproducible example? I tried to create one with your snippet, but wasn't able to reproduce this.

A simple code that runs in a single java file would be nice, like this (which is not working right now):

@Mapper
interface Issue3575Mapper {

    @Mapping(source = "a.b.c.d1", target = "name")
    D2 aToD2(A a);

}

class A {
    public B b;
}

class B {
    public C c;
}

class C {
    public D1 d1;
}

class D1 {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class D2 {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

This currently fails with Can't map property "D1 a.b.c.d1" to "String name". Consider to declare/implement a mapping method: "String map(D1 value)".

@Zegveld
Copy link
Contributor Author

Zegveld commented May 15, 2024

@Zegveld I am facing a similar issue on 1.6.0.Beta1 where the deeply nested object fields are not being mapped. Possible to reopen this issue?

Not reopening this issue, see #3577 for the discussion about behaviour of ignoreByDefault combined with (nested) mappings.
See also the release notes of 1.6.0.Beta1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants