Home > Enterprise >  how to use mapper for list<String> from DTO set to String from DTO
how to use mapper for list<String> from DTO set to String from DTO

Time:11-10

public class MessageRqDTO implements Serializable {

    private Long id;

    private String data;

    private String device;

    private String headers;

    private Boolean isProcessed;

    private String notification;

    private String referenceCode;

    private Boolean scheduled;

    private Boolean transactional;

    private Instant startFromTime;

    private Instant expirationTime;

    private List<String> identifiers = new ArrayList<>();

    private UserTokenDTO userToken;
}

first dto List identifiers

public class MessagetoMqDTO implements Serializable{
    private Long id;

    private String data;

    private String device;

    private String headers;

    private Boolean isProcessed;

    private String notification;

    private String referenceCode;

    private Boolean scheduled;

    private Boolean transactional;

    private Instant startFromTime;

    private Instant expirationTime;

    private String identifiers ;

    private UserTokenDTO userToken;
    private String clientToken;
}

second DTO use this

@Mapping(target = "messageDTO", source = "messageDTO")
MessagetoMqDTO toDto(MessageRqDTO m,String identifier,String clientToken);

Error:

java: Can't map property "String identifiers" to "List<String> identifiers". Consider to declare/implement a mapping method: "List<String> map(String value)".

CodePudding user response:

Add this method to your mapper interface:

    default String mapIdentifiers(List<String> identifiers){
        String identifiersSeparator = ",";
        return identifiers.stream().collect(Collectors.joining(identifiersSeparator));
    }
  • Related