Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Allow Builders to leverage Kotlin defaults, or kotlin builder notation when required fields are missing #14

Open
@natashashams

Description

@natashashams

ex data class in kotlin -

import com.github.pozo.KotlinBuilder

@KotlinBuilder
data class ContactInfo(val phoneNumbers: List<PhoneNumber> = emptyList(),
                       val emails: List<EmailAddress> = emptyList(),
                       val addresses: List<PostalAddress> = emptyList()
)

The create function within the generated builder looks like:

public ContactInfo create() { return new ContactInfo(phoneNumbers, emails, addresses); }

The create here uses an all args constructor. However, if the object builders never set a value for one mandatory field (addresses field, for example) the create() call using an all args constructor will try to set addresses to null, which will throw an NPE type error since this value can't be null in the target kotlin object.

I would like a way for the create() method to:

  • leverage the default values in Kotlin that an object may have (usually non-nullable types have this), setting a field to the default value if a default exists

This would be amazing and very helpful to generate more accurate builders!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions