【发布时间】:2021-12-03 15:42:44
【问题描述】:
public class ExtensionTarget {
private StringType valueString;
private BooleanType valueBoolean;
private CodeableConcept valueCodeableConcept;
}
public class ExtensionSource {
private Type value;
}
其中StringType、BooleanType 和CodeableConcept 继承自Type。
目前,我正在使用这个映射器来制作这个映射:
@Mapper(
uses = { TypeMapper.class }
)
public interface ExtensionMapper {
ExtensionTarget fhirToMpi(ExtensionSource fhirType);
}
public abstract class TypeMapper {
private final StringTypeMapper stringTypeMapper = Mappers.getMapper(StringTypeMapper.class);
private final BooleanTypeMapper booleanTypeMapper = Mappers.getMapper(BooleanTypeMapper.class);
private final CodeableConceptMapper codeableConceptMapper = Mappers.getMapper(CodeableConceptMapper.class);
public Type fhirToMpi(org.hl7.fhir.r4.model.Type fhirType) {
if (fhirType instanceof CodeableConcept) {
return this.codeableConceptMapper.fhirToMpi((CodeableConcept)fhirType);
} else if (fhirType instanceof StringType) {
return this.stringTypeMapper.fhirToMpi((StringType)fhirType);
} else if (fhirType instanceof BooleanType) {
return this.booleanTypeMapper.fhirToMpi((BooleanType)fhirType);
}
return null;
}
}
还有其他更优雅的获取方式吗?
【问题讨论】:
标签: mapstruct