I am trying to init object with default if not initialized by the user. I want the user be able not to add params in the request but I will have it with the default value.
I'm not sure what I am missing but I get Null Pointer exception.
Having this object
@Builder
@Data
@Valid
@RequiredArgsConstructor
@AllArgsConstructor
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
public class Request {
private final List<Author> authors;
private final Config config;
private Params params;
}
@Builder
@AllArgsConstructor
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
@Data
@Setter(AccessLevel.NONE)
public class Params {
@Builder.Default private boolean adultOnly = false;
}
fun main(args: Array<String>) {
val request = Request(
authors,
config(
key,
level
)
)
also using builder throw null exception
val request = QueriesRequest.builder()
.userQueries(userQueries)
.configurationKey(
QueryConfigurationKey(configurationKey,
granularityLevel))
.site(site).build()
request.params.adultOnly // throw NULL , I expected to have the default false.
}
What I am missing?