【问题标题】:Mapstruct not mapped 'addLine1' fieldMapstruct 未映射“addLine1”字段
【发布时间】:2021-08-29 00:17:58
【问题描述】:

''' @数据 @Builder(toBuilder = true) @AllArgsConstructor @NoArgsConstructor 公共类服务地址{ 私人字符串 addLine1; 私人字符串 addLine2; 私人字符串城市; 私有字符串状态; 私有字符串国家; 私人字符串 zip; 私人字符串 zipCodeExtension; }

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class OrderDTO {
private List<OrderElement> orderElement;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public static class OrderElement {

@Override
public boolean equals(Object o) {
return o == this;
}

private ServiceAddress serviceAddress;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public static class ServiceAddress {
private String addLine1;
private String addLine2;
private String city;
private String state;
private String country;
private String zip;
}
}
}

@Mapper(componentModel = "spring")
public interface test {
ServiceAddress toServiceAddress(OrderDTO.OrderElement.ServiceAddress serviceAddress);
}

@Override
public lib.dao.dto.externalconnector.onebill.ServiceAddress toServiceAddress(ServiceAddress serviceAddress) {
if ( serviceAddress == null ) 
return null;
}

ServiceAddressBuilder serviceAddress1 = lib.dao.dto.externalconnector.onebill.ServiceAddress.builder();

serviceAddress1.city( serviceAddress.getCity() );
serviceAddress1.state( serviceAddress.getState() );
serviceAddress1.country( serviceAddress.getCountry() );
serviceAddress1.zip( serviceAddress.getZip() );

return serviceAddress1.build();
}

'''

【问题讨论】:

    标签: mapstruct


    【解决方案1】:

    addLine1 之类的属性未映射的原因是因为它被视为列表属性line1 的加法器。

    您可以将该设置器命名为 setAddLine1 或禁用构建器支持(MapStruct 将使用 DTO 中的 setAddLine1)。

    【讨论】:

      猜你喜欢
      • 2021-10-09
      • 1970-01-01
      • 2020-08-02
      • 2018-07-29
      • 1970-01-01
      • 2020-04-24
      • 2020-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多