Skip to content

Preserve the order when doing Marshal & Unmarshal: gopkg.in/yaml.v2 #56077

@BLasan

Description

@BLasan

In current yaml Marshal and Unmarshal processes do not preserve the order when a specific struct is not used. However, there's an alternative approach to preserve the order which is using the yaml.MapSlice when doing Marshal & Unmarshal. However, this has an additional work around when comes to the data modification part in the interface. Wouldn't it be good to have a separate function parameter which works on preserving the oder when encoding & decoding?

yaml.Marshal(interface, True) - Second parameter will be considered for the order preservation (if it's true then order will be preserved, otherwise, order preservation is not guaranteed. Default value can be set toTrue since a user wants to have the same order when reading & writing.

yaml.Unmarshal(content, interface, True) - Same as the above method

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions