Skip to content

Apply source presence tracking recursively in nested source #1456

@birdfriend

Description

@birdfriend

Hi,

We want to apply source presence tracking recursively. For example:
//source object

public class SourceA {
  private String fieldA;
  private SourceB fieldB;

//getters & setters & hasXXX methods
...
}

public class SourceB {
  private String fieldC;
//getters & setters & hasXXX methods
...
}

//target
public class TargetObj {
  private String fieldA;
  private String fieldC;
//getters & setters
...
}

//mapper

@Mapper(nullValueCheckStrategy =  NullValueCheckStrategy.ALWAYS)
public interface TestMapper {

  @Mapping(source = "fieldB.fieldC", target = "fieldC")
  TargetObj testMap(SourceA source);
}

//The auto generated code:

public TargetObj testMap(SourceA source) {
    if(source == null) {
      return null;
    } else {
      TargetObj targetObj = new TargetObj();
      String fieldC = this.sourceFieldBFieldC(source);
      if(source.hasFieldB()) {
        targetObj.setFieldC(fieldC);
      }

      if(source.hasFieldA()) {
        targetObj.setFieldA(source.getFieldA());
      }

      return targetObj;
    }
  }
...

When mapping fieldC, source presence tracking has only applied to it's parent object,

if(source.hasFieldB()) {
        targetObj.setFieldC(fieldC);
      }

However we want to apply source presence tracking recursively:

if(source.hasFieldB() && source.getFieldB().hasFieldC()) {
        targetObj.setFieldC(fieldC);
      }

Is this some feature you can support? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions