DDD validation on full object graph

@Value
@Builder
public class Parent {

    @NotNull
    private String firstName;
    private Child child;
@Builder
public class Child {

    @NotNull
    private String firstName;

here is my challenge, we are doing DDD and we do the validation of objects within constructor or via a build method (builder pattern). What's I would like to achieve is to be able to construct the full object tree in a way that I can collect all validation errors.

As you can see with the following code, I will with this only collect the errors of the child missing the missing firstname of the parent.

Note that these objects are created manually, otherwise, I would just add @Valid's and such, but I don't think this can work when you do build objects manually.

FYI : I use the spring boot stack.

Parent.builder()
                .firstName(null)
                .child(Child.builder()
                        .firstName(null)
                        .build())
                .build();


from Recent Questions - Stack Overflow https://ift.tt/3cBGo04
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation