I am learning to use MapStruct.
I have the following custom mapping configuration that maps a List comes from JPA entity to DTO String that way:
@Mapper(componentModel = "spring")
public interface StatusMapper {
@Mapping(target = "statusCode",
expression = "java(entity.getStatuses().get(entity.getStatuses().size() - 1).getStatus())")
@Mapping(target = "details",
expression = "java(entity.getStatuses().get(entity.getStatuses().size() - 1).getMessage())")
StatusResponse map(MyEntity entity);
}
My problem with this solution is that the Java code in the expression actually is a string and the IDE (e.g. IntelliJ) is not checking the syntax of this "java" code.
Maybe after a refactor this piece of code will not work anymore because I renamed the related field.
And if I add a null check to the expression then this piece of code will be more longer, and longer code can have more typos.
Can I write here somehow a real java code instead of using this Java expression string?