Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jakarta.annotation.Nullable is not being considered with @Builder.Constructor #1522

Open
cvgaviao opened this issue Jun 29, 2024 · 0 comments

Comments

@cvgaviao
Copy link

cvgaviao commented Jun 29, 2024

Hello,
I'm trying to set a @Builder.Constructor where I have some @Nullable properties defined in an interface's method being implemented by the class.

I have this on my parent class:

@Value.Style(nullableAnnotation = "jakarta.annotation.Nullable")
public abstract class BaseEntity {
    @Id
    @GeneratedValue
    @Nullable
    public Long id;
...
}

and this interface that is share between the Entity and some DTOs:

public interface IUser {

    @NotBlank
    @Size(min = 3, max = 50)
    String getName();

    @Nullable
    @Size(min = 3, max = 150)
    String getSurname();
}

And I have this child class:

public class User extends BaseEntity implements IUser {
    @Builder.Constructor
    public User(@Builder.Parameter Long id, String name, String surname) {
        super(id);
        this.name = name;
        this.surname = surname;
    }
}

When I run a test where I create a new User without the surname, I got this error, signalizing that the @Nullable was not considered:

java.lang.IllegalStateException: Cannot build User, some of required attributes are not set [surname]
	at com.app_mngt.entities.UserBuilder.checkRequiredAttributes(UserBuilder.java:202)
	at com.app_mngt.entities.UserBuilder.build(UserBuilder.java:176)
	at com.app_mngt.mappers.UserMapperTest.testEntityToDtoMapping(UserMapperTest.java:41)

Am I missing something ?

@cvgaviao cvgaviao changed the title jakarta.annotation.Nullable is not being considered for on Interface method. jakarta.annotation.Nullable is not being considered Jun 29, 2024
@cvgaviao cvgaviao changed the title jakarta.annotation.Nullable is not being considered jakarta.annotation.Nullable is not being considered with @Builder.Constructor Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant