I'm facing some difficulties while trying to use Mapper annotation functionality of spring. I would like to use the mapper to map an object of Map in java as follows:
HostCounters :
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HostsCounters {
private Map<String,Map<String,Long>> hostsList;
}
Mapper :
@Mapper(componentModel = "spring")
public interface ResponseMapper {
GeneralResponse toResponse(SevCount sevCount, HostsCounters hostsList, List<RegDAO> Reg);
}
GeneralRespone:
@Data
@NoArgsConstructor
public class GeneralResponse {
private List<RegDAO> Reg;
private HostsCounters hostsList;
private SevCount sevCount;
}
Error:
Can't map property "java.util.Map> hostsList" to " HostsCounters hostsList". Consider to declare/implement a mapping method
Just use:
@Mapping(source = "hostsList", target = "hostsList")
GeneralResponse toResponse(SevCount sevCount, HostsCounters hostsList, List<RegDAO> Reg);
But I would strongly advise you to get rid of identical names with different meanings:
HostsCounters hostsList -> HostsCounters hostsLists
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.