0
votes

I am using mapstruct for mapping in my Spring Boot application. My source object is as below:

Customer{
    String id;
    String name;
    List<Facility> facilityList;
}

Facility{
    String fId;
    String fName;
    Integer off;
}

Before actual mapping of source to target object, I want to replace all empty value of string and list of source with null (without manual mapping)?

How to achieve this with mapstruct or any Java libraries?

1

1 Answers

2
votes

You could use the expression attribute with @Mapping annotation like this :

@Mapping(target = "fName", expression = "java(src.name.isEmpty() ? null : src.name)")
Target convert(Source src);