我有一个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;
}
并通过使用ModelMapper将其传递给DocumentDto类:DocumentDto documentDto = modelMapper.map(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
答案 0 :(得分:0)
我没有正确设置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;
}