Skip to content

Empty arrays are turned into nil  #188

@pebrc

Description

@pebrc

When parsing empty arrays from YAML to config objects and unpacking into an untyped representation like map[string]interface{} arrays in the original source are turned into nil. Marshalling back to YAML this turns into null and is thereby not round-trippeable through ucfg:

Consider:

node.roles: []
input, err := yaml.Unmarshal(`node.roles: []`)
...
c, err := NewConfig([]byte(input))
...
var output map[string]interface{}
err = c.Unpack(output)
...
yaml.Marshal(output)

leaves us with:

node.roles: null

We have been hit in the ECK operator a couple of times by this issue:

We are using untyped map[string]interface{} target data structures in the operator for application configuration because it is difficult for us to model each Elastic stack application's configuration completely and for all versions of the Elastic stack that we need to support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions