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

Add less verbose ways to say that types are not nullable by default #107

Closed
gilberto-torrezan opened this issue Sep 14, 2021 · 3 comments
Closed
Labels
enhancement New feature or request Epic help wanted Extra attention is needed hilla Issues related to Hilla

Comments

@gilberto-torrezan
Copy link
Contributor

With the introduction of V21, parameter types and return types from endpoints are now nullable by default. Making an type not-nullable when accessed via TypeScript requires the use of an "@nonnull" annotation.

The problem is: in order to make the Typescript calls cleaner, every single attribute or return type needs to be annotated with @Nonnull, which becomes quite verbose. Also when using Lists, annotating parameterized types is not convenient (some IDEs have poor support for such structure). Example: @Nonnull List<@Nonnull Person>.

There should be an easier way for the developers to say that either all Endpoints or some subset of Endpoints have all types not-nullable (basically the behavior up to V20).

This can be done in the following ways:

  • Introduce a class level @Nonnull annotation, that makes all types declared in the methods of the class @Nonnull by default;
  • Introduce a configuration flag in the pom.xml to make all Endpoints @Nonnull by default (the behavior from V20);
  • Having a separate configuration file with types that are always @Nonnull (or the opposite, a list with only nullables).

We are open to feedback on which solution would be the best (or other solutions as well).

@gilberto-torrezan gilberto-torrezan added enhancement New feature or request help wanted Extra attention is needed hilla Issues related to Hilla Epic labels Sep 14, 2021
@Artur-
Copy link
Member

Artur- commented Sep 14, 2021

I think we should avoid a global configuration flag because this would mean that you no longer can understand how an endpoint class works by looking at it and its parent class.

@knoobie
Copy link

knoobie commented Sep 14, 2021

Spring (fusion already depends on it) has already a quite good (and IDE supported) way of reducing boilerplate with the specific annotations for fields and apis - see https://www.baeldung.com/spring-null-safety-annotations for more informations.

@haijian-vaadin
Copy link
Contributor

thanks for the suggestion @knoobie, we decided to go with the package level annotation for nonnullable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Epic help wanted Extra attention is needed hilla Issues related to Hilla
Projects
None yet
Development

No branches or pull requests

5 participants