当前位置: 首页 > 知识库问答 >
问题:

ModelMapper配置错误

葛桐
2023-03-14

我有一个JSON:

{
    "signatureOptions": {
        "signatureType": "string",
        "digestAlgorithmName": "string",
        "signaturePackagingType": "string",
        "documentType": "string"
       },
    "pdfSignatureOptions": {
        "signatureTextColor": integerValue,
        "signatureTextFontSize": floatValue,
        "fontFamily": "string",
        "fontStyle": "string",
        "signatureImageContent": "string",
        "signatureText": "string",
        "signaturePosX": floatValue,
        "signaturePosY": floatValue,
        "signaturePage": integerValue
       },
       "enableArchive": false,
       "archiverNames": [
        "string"
       ],
    "toSignContent": "String"
}

我创建了以下pojo

@Getter @Setter
public class SignatureOptions {
    private String signatureType;
    private String digestAlgorithmName;
    private String signaturePackagingType;
    private String documentType;

    // constructor
}

@Getter @Setter
public class PdfSignatureOptions {
    private int signatureTextColor;
    private float signatureTextFontSize;
    private String fontFamily;
    private String fontStyle;
    private String signatureImageContent;
    private String signatureText;
    private float signaturePosX;
    private float signaturePosY;
    private int signaturePage;

    // constructor
}

@Getter @Setter
public class DocumentToSignRestRequest {
    private SignatureOptions signatureOptions = new SignatureOptions();
    private PdfSignatureOptions pdfSignatureOptions = new PdfSignatureOptions();
    private boolean enableArchive;
    private ArrayList< Object > archiverNames = new ArrayList <>();
    private String toSignContent;

    // constructor
}

在我的控制器中,我有一个@PostMapping方法,我尝试检索DocumentToSignRestRequest:

@PostMapping(
    value="/sign",
    consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE },
    produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }
)
public DocumentRest getDocumentSigned(@RequestBody DocumentToSignRestRequest  documentToSignRestRequest) throws Exception {
    // instanciate empty return object
    DocumentRest returnValue = new DocumentRest();

    // Map the documentToSignRestRequest with a DTO Object
    ModelMapper modelMapper = new ModelMapper();
    DocumentDto documentDto = modelMapper.map(documentToSignRestRequest, DocumentDto.class);

    // Call the documentService layer and assign the return to a new DOcumentDto
    DocumentDto signedDocument = documentService.signDocument(documentDto);
    returnValue = modelMapper.map(signedDocument, DocumentRest.class);
    // return a rest object with signedDocument values
    return returnValue;
}

并使用模型映射器将其传递给DocumentDto类:DocumentDto DocumentDto=ModelMapper。地图(documentToSignRestRequest,DocumentDto.class);

这个类的不同属性与组成我要映射的类的不同类中的属性具有相同的名称。

@Getter @Setter
public class DocumentDto implements Serializable {

    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private static final long serialVersionUID = 6835192601898364280L;

    // document information from DocumentRest
    private String documentName;
    private String documentPath;
    private boolean isDocumentSigned;
    // SignatureOptions values
    private String signatureType;
    private String digestAlgorithmName;
    private String signaturePackagingType;
    private String documentType;
    // PdfSignatureOptionsObject values
    private int signatureTextColor;
    private float signatureTextFontSize;
    private String fontFamily;
    private String fontStyle;
    private String signatureImageContent;
    private String signatureText;
    private float signaturePosX;
    private float signaturePosY;
    private int signaturePage;

    private boolean enableArchive;
    private ArrayList< Object > archiverNames = new ArrayList <>();
    private String toSignContent;
}

当我使用邮递员时,我收到一条错误消息

ModelMapper配置错误:\r\n\r\n1)目标属性com.app.ws.certeuropews.shared.dto.DocumentDto.setSignatureType()匹配多个源属性层次结构:\n\n\tcom.app.ws.certeuropews.ui.model.request.DocumentToSignRestRequest.getSignatureOptions()/

这个问题的解决方案是什么。我在看ModelMapper指南,我想知道。。http://modelmapper.org/examples/projection/#example-1

共有1个答案

颛孙智勇
2023-03-14

我没有正确设置DTO层:

@Getter
@Setter
public class DocumentDto implements Serializable {

    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private static final long serialVersionUID = 6835192601898364280L;

    // document information from DocumentRest
    private String documentName;
    private String documentPath;
    private boolean isDocumentSigned;
    // SignatureOptions values
    private SignatureOptionsDto signatureOptionsDto;
    // PdfSignatureOptionsObject values
    private PdfSignatureOptionsDto pdfSignatureOptionsDto;

    private boolean enableArchive;
    private ArrayList< Object > archiverNames = new ArrayList <>();
    private String toSignContent;
}
 类似资料:
  • 当我试图将布尔映射到字符时,我看到了无法用ModelMapper解释的行为。 (我已经检查过了,这个问题与龙目岛无关)。 它产生字符“t”和“f”,而不是我想要的“Y”和“N”。 项目(实例=t) 项目(实例=f) 有人知道ModelMapper配置应该是什么样子吗?

  • 我试图使用命令“java-jar XXXX.jar”运行spring boot项目,但出现以下错误: 错误:发生JNI错误,请检查您的安装并重试线程“main”java.lang.NoClassDefFoundError中的异常:org/modelmapper/modelmapper位于java.lang.Class.getDeclaredMethods0(本机方法),java.lang.Clas

  • 我有两个类使用ModelMapper将实体转换为DTO。在每个类中,我都在类的构造函数中配置了ModelMapper,以避免将所有关系转换为DTO并获得StackOverflow Error。 公司服务impl 公司利润 当我运行应用程序时,我得到一个错误: com的映射已存在。特写国际。批准dtos。公司服务模块化。setCompanyService()。 如何为ModelMapper提供两个配

  • 版本介绍 百度移动统计提供两种版本的Crash错误统计功能:标准版、详细Crash版。 标准版:采集的Crash日志内容较少,包含关键的LastBacktrace等信息。 详细Crash版:采集的Crash日志内容丰富,接近iOS系统完整的Crash格式,包含LastBacktrace、thread等信息。 由于加入详细的Crash统计功能会使SDK的体积增大,所以请结合自身业务场景,合理选择SD

  • 百度移动统计提供了错误统计功能。包括错误报告,错误路径等。 由于加入详细的错误统计上报功能,会导致SDK的整体大小变大。故我们针对那些只需要基本的错误次数统计功能的用户提供了标准的java错误统计功能,集成在了应用分析(无埋点)和应用分析(手动埋点)SDK中;针对需要native crash错误信息的用户,提供了附加的Crash版本。

  • 这是我的DTO: 这是我的实体: 我想配置我的ModelMapper将Tag#id映射到TagVolumeDTO#idTag。这可能吗?