【问题标题】:Problem with NullValueCheckStrategy.ALWAYS (mapstruct 1.3.1)NullValueCheckStrategy.ALWAYS 问题(mapstruct 1.3.1)
【发布时间】:2020-06-30 11:46:25
【问题描述】:

在将 mapstruct 从 1.2.0 升级到 1.3.1 后,我注意到注释 @Mapper(nullValueCheckStrategy=NullValueCheckStrategy.ALWAYS) 无效。 它是新 mapstruct 版本的错误吗?

例子:

以下代码:

String id = getTestId( testId);
if ( id != null ) {
    testCase.setTestCaseId( id );
}
else {
   testCase.setTestCaseId( null );
}

而右边是:

String id = getTestId( testId);
if ( id != null ) {
   testCase.setTestCaseId( id );
}

【问题讨论】:

标签: java mapping mapstruct


【解决方案1】:

随着NullValuePropertyMapping 的出现,这种行为变得更加重要。我认为发行说明中也提到了这一点。查看文档:

1:更新方法(@MappingTarget) https://mapstruct.org/documentation/stable/reference/html/#mapping-result-for-null-properties

2:常规(非更新)方法 https://mapstruct.org/documentation/stable/reference/html/#checking-source-property-for-null-arguments

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2019-03-23
    相关资源
    最近更新 更多