Ich habe ein Frühlingsprojekt und mit Jackson für JS Serialisierung und Deserialisierung.Validieren verschachtelten Objekt in Jackson
Und ich habe diese DTOs definiert,
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
}
Sie können sehen, über dem habe ich gesetzt habe ich @NotNull
Annotation Set für die Felder certificate
& dnzZone
.
Allerdings scheint dieses JSON erfolgreich zu parsen. Dies geschieht nur bei verschachtelten Objekten.
{
"orgId":"1001",
"certificateType":"Single Use",
"privateCertificate":{
"pkcs12":"test",
"certificatePassword":"Test"
},
"publicCertificate":{
}
}
Wenn ich die Post folgende es wird die Validierung nicht als @NotNull
für publicCertificate
{
"orgId":"1001",
"certificateType":"Single Use",
"privateCertificate":{
"pkcs12":"test",
"certificatePassword":"Test"
}
}
I @Valid
Satz für die @RequestBody
im RestController
haben festgelegt ist.
Irgendeine Idee, was könnte das verursachen ??