模型映射器映射 Map<String,Object> 到 class,它扩展了另一个通用的 class 不适用于列表字段

Model mapper mapping Map<String,Object> to class which extends another generic class not working for list field

我正在尝试使用模型映射器从 Map 创建我的自定义配置对象。除了来自 Generic super class.

fields 属性 之外,所有内容都已正确映射

我的目标对象是

public class ADParserConfig extends CustomParserConfig<ADParserConfigField> {

private String pattern;

public String getPattern() {
    return pattern;
}

public void setPattern(String pattern) {
    this.pattern = pattern;
}

}

这扩展了通用 class CustomParserConfig

public class CustomParserConfig<T extends CustomParserConfigField> {

protected List<T> fields;
protected String timeStampField;

public List<T> getFields() {
    return fields;
}

public void setFields(List<T> fields) {
    this.fields = fields;
}

public String getTimeStampField() {
    return timeStampField;
}

public void setTimeStampField(String timeStampField) {
    this.timeStampField = timeStampField;
}
}

CustomParserConfigField 是

public class CustomParserConfigField {

protected String name;
protected Integer index;
protected String type;
protected String format;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Integer getIndex() {
    return index;
}

public void setIndex(Integer index) {
    this.index = index;
}

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

public String getFormat() {
    return format;
}

public void setFormat(String format) {
    this.format = format;
}
}

我正在尝试使用以下函数映射地图

ADParserConfig adParserConfig = getConfig(map,ADParserConfig.class);

 public  <T extends CustomParserConfig> T getConfig(Map<String,Object> configObject, Class<T> classType){
    ModelMapper modelMapper = new ModelMapper();

    return modelMapper.map(configObject,classType);

}

除了 fields 之外的所有内容都已正确映射为下面的地图。

{fields=[{name=timeStamp, type=timestamp, format=dd/mm/yyyy HH:MM:SS a}, {name=logName, type=string}], pattern=(?<timeStamp>\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}:\d{2}\s[AMPMampm]{2})?\s(LogName=(?<logName>[\w\s\W]+))?\sSourceName=(?<sourceName>[\w\s\W]+)\sEventCode=(?<eventCode>[0-9]*), timeStampField=timestamp}

请帮忙。为什么问题只发生在字段对象上?我是否需要在映射器配置中指定其他内容?

它看起来像是一个错误,已被 #370

修复