Skip to content

Make default values available from descriptors #3066

@rnett

Description

@rnett

What is your use-case and why do you need this feature?

When generating a schema from descriptors, or working with the descriptor tree in other ways (like my particular use-case: generating a UI form based on it), it would be nice to be able to access the default values of elements.

The biggest reason across all of these use-cases is documenting default values, e.g. in a schema or openAPI spec.

Describe the solution you'd like

A SerialDescriptor.getElementDefaultValue(index: Int): Any? or : (() -> Any?)? method that gets the default value if there is one or null if not, and a SerialDescriptor.elementHasDefaultValue(index: Int): Boolean method. The second one may be redundant with isElementOptional - I don't know whether the semantics are a 100% match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions