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

The resulting implementation class does not have a set value #3578

Closed
mawl01 opened this issue Apr 26, 2024 · 5 comments
Closed

The resulting implementation class does not have a set value #3578

mawl01 opened this issue Apr 26, 2024 · 5 comments

Comments

@mawl01
Copy link

mawl01 commented Apr 26, 2024

Expected behavior

   public class SysManagerApplicationMapImpl implements SysManagerApplicationMap {
        public SysManagerApplicationMapImpl() {
        }

    public List<SysManagerApplicationListModel> toModelList(List<SysManagerApplicationDO> sysManagerApplicationDO) {
        if (sysManagerApplicationDO == null) {
            return null;
        } else {
            List<SysManagerApplicationListModel> list = new ArrayList(sysManagerApplicationDO.size());
            Iterator var3 = sysManagerApplicationDO.iterator();

            while(var3.hasNext()) {
                SysManagerApplicationDO sysManagerApplicationDO1 = (SysManagerApplicationDO)var3.next();
                list.add(this.sysManagerApplicationDOToSysManagerApplicationListModel(sysManagerApplicationDO1));
            }

            return list;
        }
    }

    protected SysManagerApplicationListModel sysManagerApplicationDOToSysManagerApplicationListModel(SysManagerApplicationDO sysManagerApplicationDO) {
        if (sysManagerApplicationDO == null) {
            return null;
        } else {
            SysManagerApplicationListModel sysManagerApplicationListModel = new SysManagerApplicationListModel();
            sysManagerApplicationListModel.setAppName(sysManagerApplicationDO.getAppName())
            return sysManagerApplicationListModel;
        }
    }
}

Actual behavior

    public class SysManagerApplicationMapImpl implements SysManagerApplicationMap {
        public SysManagerApplicationMapImpl() {
        }

    public List<SysManagerApplicationListModel> toModelList(List<SysManagerApplicationDO> sysManagerApplicationDO) {
        if (sysManagerApplicationDO == null) {
            return null;
        } else {
            List<SysManagerApplicationListModel> list = new ArrayList(sysManagerApplicationDO.size());
            Iterator var3 = sysManagerApplicationDO.iterator();

            while(var3.hasNext()) {
                SysManagerApplicationDO sysManagerApplicationDO1 = (SysManagerApplicationDO)var3.next();
                list.add(this.sysManagerApplicationDOToSysManagerApplicationListModel(sysManagerApplicationDO1));
            }

            return list;
        }
    }

    protected SysManagerApplicationListModel sysManagerApplicationDOToSysManagerApplicationListModel(SysManagerApplicationDO sysManagerApplicationDO) {
        if (sysManagerApplicationDO == null) {
            return null;
        } else {
            SysManagerApplicationListModel sysManagerApplicationListModel = new SysManagerApplicationListModel();
            return sysManagerApplicationListModel;
        }
    }
}

Steps to reproduce the problem

1. pom.xml configuration

   <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.8.1</version>
                  <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                      <annotationProcessorPaths>
                          <path>
                              <groupId>org.mapstruct</groupId>
                              <artifactId>mapstruct-processor</artifactId>
                              <version>1.5.5.Final</version>
                          </path>
                      </annotationProcessorPaths>
                  </configuration>
              </plugin>
          </plugins>
      </build>

2. class

@Mapper
public interface SysManagerApplicationMap {
        SysManagerApplicationMap INSTANCE = Mappers.getMapper(SysManagerApplicationMap.class);

        List<SysManagerApplicationListModel> toModelList(List<SysManagerApplicationDO> sysManagerApplicationDO);
}

MapStruct Version

1.5.5.Final

@mawl01 mawl01 added the bug label Apr 26, 2024
@filiphr
Copy link
Member

filiphr commented Apr 27, 2024

@mawl01 the code you've shared does not look like code that MapStruct generates. It looks like code that has been decompiled from bytecode. Can you please share an example project where we can reproduce this

@filiphr filiphr added the closing-when-no-response Marking issues that are ready to be closed label Apr 27, 2024
@alantanlc
Copy link

alantanlc commented May 14, 2024

Facing the same issue using 1.6.0.Beta1 where deeply nested source objects are missing the setter codes in the target object.

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.

MapStruct Version

1.6.0.Beta1

@thunderhook
Copy link
Contributor

@alantanlc As I wrote in #3575, could you please provide a reproducer?

@alantanlc
Copy link

@thunderhook ok i will share a reproducible example soon, thank you!

@filiphr
Copy link
Member

filiphr commented Jun 1, 2024

Closing this for now. Once we have a reproducer from @alantanlc we'll reopen it.

@filiphr filiphr closed this as completed Jun 1, 2024
@filiphr filiphr removed closing-when-no-response Marking issues that are ready to be closed bug labels Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants