简体   繁体   English

Mapstruct在实现中添加注释

[英]Mapstruct add annotations in implementation

I've got entity with byte[] field, same as in my DTO object. 我的实体具有byte[]字段,与我的DTO对象相同。 In both classes those fields are annotated as @NotNull . 在这两个类中,这些字段都注释为@NotNull The problem is that mapstruct generate code like that: 问题是mapstruct生成如下代码:

(@javax.validation.constraints.NotNull :: byte)[] data = file.getData();

instead of 代替

byte[] data = file.getData()

I can use annotation like that 我可以这样使用注释

@Mapping(ignore = true, source = "data", target = "data")

to "solve" this problem, and set those fields in my service, but i don't think it's best solution. 来“解决”这个问题,并在我的服务中设置这些字段,但是我认为这不是最好的解决方案。

Problem only occurs with this byte[] , there is no problem with other @NonNull fields. 仅此byte[]出现问题,其他@NonNull字段则没有问题。

This is a known bug in MapStruct 1.2.0.Final. 这是MapStruct 1.2.0.Final中的一个已知错误。 It has been fixed since 1.3.0.Beta2 (latest release at the time of this answer). 自1.3.0.Beta2(此答案发布时的最新版本)以来已修复。

The reported issue for this was mapstruct/mapstruct#1558 . 报告的问题是mapstruct / mapstruct#1558

The problem can only be seen when annotations of the type ElementType.TYPE_VAR were used for primitive arrays. 仅当将ElementType.TYPE_VAR类型的注释用于基本数组时,才能看到此问题。 The same problem can be seen if int[] (for example) is used. 如果使用int[] (例如),则会看到相同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM