We have an endpoint with a lot of boolean on it, with default values. I wanted to encapsulate those into an object thanks to the @ParameterObject annotation.
However, I haven't found a way to set default values for it. My idea was to have something similar to what @PageableDault does.
Here the endpoint:
public List<Person> getPersons(@ParameterObject SearchCriteria profileSearchCriteria) {
// beautiful code
}
And here the object (it uses Lombok but shouldn't have an impact I would say :)):
@Builder
@Data
@Jacksonized
public class ProfileSearchCriteria {
@Builder.Default
private boolean criteria1 = false;
@Builder.Default
private boolean criteria2 = false;
@Builder.Default
private boolean criteria3 = false;
Do you know how can I setup default values for the @ParameterObject annotation?
You need to put @Schema with the default value above the ProfileSearchCriteria fields. Like this:
@Builder
@Data
@Jacksonized
public class ProfileSearchCriteria {
@Builder.Default
@Schema(defaultValue = "false")
private boolean criteria1 = false;
@Builder.Default
@Schema(defaultValue = "false")
private boolean criteria2 = false;
@Builder.Default
@Schema(defaultValue = "false")
private boolean criteria3 = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With