Ive는 json 직렬화 및 직렬화 복원을 위해 spring 프로젝트를 사용하고 jackson을 사용합니다.잭슨에서 중첩 된 오브젝트 유효성 확인
그리고 나는이 DTO들 정의한,
CertManDTO,
public class CertManDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private UUID certificateId;
@NotNull
private Long orgId;
@NotNull
private CertificateType certificateType;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@NotNull
private PublicCertificateDTO publicCertificate;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private PrivateCertificateDTO privateCertificate;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private ZonedDateTime expiryDate;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private ZonedDateTime createdDate;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private ZonedDateTime updatedDate;
// Getters and setters
}
PublicCertificateDTO,
public class PublicCertificateDTO implements Serializable {
private static final long serialVersionUID = 1L;
@JsonIgnore
private Long id;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@NotNull
private String certificate;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@NotNull
private String dnsZone;
// Getters and setters
}
PrivateCertificateDTO,
public class PrivateCertificateDTO implements Serializable {
private static final long serialVersionUID = 1L;
@JsonIgnore
private Long id;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private String pkcs12;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private String privateCertificatePassword;
// Getters and setters
}
당신은 볼 수 있습니다 내가 설정 한 위의 @NotNull
주석 집합은 certificate
& dnzZone
입니다.
게시하는 중이 JSON을 성공적으로 구문 분석하는 것 같습니다. 이것은 중첩 된 객체에서만 발생합니다.
{
"orgId":"1001",
"certificateType":"Single Use",
"privateCertificate":{
"pkcs12":"test",
"certificatePassword":"Test"
},
"publicCertificate":{
}
}
내가 게시 할 경우 @NotNull
가 나는 RestController
의 @RequestBody
에 대한 @Valid
설정을해야합니까 publicCertificate
{
"orgId":"1001",
"certificateType":"Single Use",
"privateCertificate":{
"pkcs12":"test",
"certificatePassword":"Test"
}
}
설정되어대로 검증을 실패합니다 다음.
어떤 생각이 원인 일 수 있습니까 ??