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

New annotation for creating isomorphic class with nullable fields #91

Open
sschuberth opened this issue Nov 13, 2023 · 0 comments
Open

Comments

@sschuberth
Copy link

I'm not sure whether this is in scope of this library, but I wanted to mention the idea:

Based on an existing data class which has non-nullable properties, I'm often in the need to create a variant of that class whose properties are the same, but nullable. A use-case is e.g. configuration classes with optional / nullable properties, that are turned into "full configuration classes" by applying non-null defaults to nullable properties, resulting in a configuration class with all non-nullable properties.

So, how about introducing an annotation named e.g. @CopyAsNullable that could be used like

@CopyAsNullable(to = "OptionalPerson")
data class Person(val name: String, val friends: List<Person>)

which would generate the class

data class OptionalPerson(val name: String? = null, val friends: List<Person>? = null)

The application of the default = null values could be made optional via another argument to @CopyAsNullable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant