我在生成地图实现时有一个特殊的问题,我需要映射一个空对象的属性。代码在ObjectRequestMapper
中是这样的:
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, nullValueCheckStrategy =
NullValueCheckStrategy.ALWAYS, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL, uses = {
WrapperGrpcMapper.class, AddressRequestMapper.class })
public interface ObjectRequestGrpcMapper {
@Mapping(target = "wcsStoreId", source = "storeId")
@Mapping(target = "linesList", source = "lines")
ObjectRequest map(Long storeId, @Context String countryCode, List<ObjectLines> lines, Address address);
ObjectRequestLine lineToProto (ObjectLine line);
}
和AddressRequestMapper
:
public interface AddressRequestMapper {
default Address toProto(Address address, @Context String countryCode){
return this.map(address, countryCode);
}
Address map(Address address, String countryCode);
}
当我调用ObjectRequest
的映射并传递带有countryCode = "EN"
的所有参数且对象地址为null时,AddresRequestMapper
的映射器不适用,因为ObjectRequestMapper
会检查{ {1}},然后不将Address == null
映射到地址
有可能针对这种情况找到解决方案吗?
谢谢
答案 0 :(得分:0)
如果您需要获取而不是“ Address == null”->“ new Address()”,请进行更改:
nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT