Skip to content

New annotation for creating isomorphic class with nullable fields #91

@sschuberth

Description

@sschuberth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions