We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flow
inline
I am trying to inline structure with flow style serialization. If i use flow and inline tags together, then only inline works, but flow doesn't.
As workaround of this situation i had to build yaml node by myself. For example:
func newFlowMapNode(p map[string]int) *yaml.Node { n := &yaml.Node{ Kind: yaml.MappingNode, Style: yaml.FlowStyle, Content: []*yaml.Node{}, } for k, v := range p { n.Content = append(n.Content, &yaml.Node{Kind: yaml.ScalarNode, Value: k}) n.Content = append(n.Content, &yaml.Node{Kind: yaml.ScalarNode, Value: fmt.Sprintf("%d", v)}) } return n }
Then if i am trying to serialize this yaml.Node into string i can got desired result like {a: 1, b: 2}.
{a: 1, b: 2}
package main import ( "testing" "gopkg.in/yaml.v3" ) type InlineFlow struct { Map map[string]int `yaml:",inline,flow"` } type FlowInline struct { Map map[string]int `yaml:",flow,inline"` } func TestYamlFlowInline(t *testing.T) { data := map[string]int{"a": 1} a := &InlineFlow{Map: data} b := &FlowInline{Map: data} resA, err := yaml.Marshal(a) if err != nil { t.Error(err) } expected := "{a : 1}" if string(resA) != expected { t.Errorf("wrong result: expected: %s, actual: %s", expected, resA) } resB, err := yaml.Marshal(b) if err != nil { t.Error(err) } if string(resB) != "{a: 1}" { t.Errorf("wrong result: expected: %s, actual: %s", expected, resB) } }
Thank you!
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I am trying to inline structure with flow style serialization.
If i use
flow
andinline
tags together, then onlyinline
works, butflow
doesn't.As workaround of this situation i had to build yaml node by myself. For example:
Then if i am trying to serialize this yaml.Node into string i can got desired result like
{a: 1, b: 2}
.Repro test
Thank you!
The text was updated successfully, but these errors were encountered: