Skip to content

RepositoryConstraintViolationExceptionMessage produces inaccurate output [DATAREST-805] #1181

@spring-projects-issues

Description

@spring-projects-issues

Christian Bongiorno opened DATAREST-805 and commented

The invalidValue field of RepositoryConstraintViolationExceptionMessage.ValidationError is a string even if the failed member is of another type because it is being string formatted. By maintaining the original type we allow better debugging by expressing more closely the true type input and not just its toString() and also allow the original marshaller/unmarshaller to express the object as is more appropriate.

Example input:

{
    "givenName" : "null",
    "familyName" : "Bongiorno",
    "dob" : "2007-12-03",
    "nationalId" : "12345687",
    "photo" : null
    
}

or

{
    "givenName" : null,
    "familyName" : "Bongiorno",
    "dob" : "2007-12-03",
    "nationalId" : "12345687",
    "photo" : null
    
}

example output

{
    "errors": [
        {
            "entity": "Worker",
            "message": "may not be null",
            "invalidValue": "null",
            "property": "givenName"
        }
    ]
}

Entity:

@Entity
public class Worker {

    @Id
    private Long id;

    @NotNull
    @Pattern(regexp = "[^null]", message = "may not be null")
    private String givenName;

    @NotNull
    private String familyName;

    private LocalDate dob;

    private String nationalId;

    private byte[] photo;
}

I intentionally added a silly validation constraint to demonstrate


Affects: 2.4.4 (Gosling SR4), 2.5.1 (Hopper SR1)

Referenced from: commits 29f90e0, c8abdf0

Backported to: 2.5.2 (Hopper SR2)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions