我正在尝试使用mapstruct框架(最终版本1.3.0)将POJO映射到protobuf消息。一切正常,除非我从一个List属性映射到protobuf重复字符串属性。我通过下面的一个小示例附加了我的问题。
我已经尝试遍历示例,并在https://github.com/mapstruct/mapstruct/issues/1338处进行评论。但是解决方案对我来说还不清楚。
java
message TestProto {
repeated string id = 1;
}
@Data//property has getter and setter
@NoArgsConstructor//No argument constructor
public class TestClass{
private List<String> id;
}
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface TestMapper {
TestMapper INSTANCE = Mappers.getMapper(TestMapper.class);
@Mapping(target = "idList", source = "id")
TestProto map(TestClass model)
}
错误:
error: ProtocolStringList is abstract; cannot be instantiated
ProtocolStringList protocolStringList = new ProtocolStringList();
不幸的是,idList的类型为ProtocolStringList,框架有些混乱。是否有我缺少的技巧或此功能尚未实现!