I am trying to set null values to database of empty values from JSON payload. This problem caused beacause I have unique constraints on social
entity fields.
I have request DTO that looks like:
@Value
@With
@Builder
@Jacksonized
public class AccountCreateRequest {
@NotBlank
String firstName;
String phone;
@Password
@NotBlank
String password;
@Email(message = "Email is not valid.")
@NotBlank
String email;
@NotBlank
String role;
SocialDto social;
}
Nested social DTO looks like
@Value
@Builder
@Jacksonized
public class SocialDto {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
String telegramId;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
String linkedinLink;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
String githubLink;
}
Json example:
{
...fields...,
social: {
telegramId: "",
githubLink: "",
...
}
}
This JSON object is deserialized with social empty strings and doesn't ignore that values. Moving annotation to the class level - didn't help for me.
How could I fix this problem?