我有一个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;
}当我使用postman时,我得到一条错误消息:
目标属性com.app.ws.certeuropews.shared.dto.DocumentDto.setSignatureType()与多个源属性hierarchies:\n\n\tcom.app.ws.certeuropews.ui.model.request.DocumentToSignRestRequest.getSignatureOptions()/匹配的ModelMapper配置错误:\r\n\r\n1
这个问题的解决方案是什么?我在看ModelMapper指南,我想知道..http://modelmapper.org/examples/projection/#example-1
发布于 2019-10-09 20:39: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;
}https://stackoverflow.com/questions/58303906
复制相似问题