Hummus now supports nesting a hummus-tagged struct as a field inside a parent struct, or an array of hummus-tagged structs as fields inside parent structs. Like so:
Example 1
type Inner struct {
A string `hummus:"innerchild.fieldA"`
B string `hummus:"innerchild.fieldB"`
}
input := struct {
C string `hummus:"fieldC"`
I Inner `hummus:"inner"`
}{
C: "C_val",
I: Inner{
A: "A_val",
B: "B_val",
},
}
outJSON, err := hummus.Marshal(input)
This gives us the following JSON:
{
"fieldC": "C_val",
"inner": {
"innerchild": {
"fieldA": "A_val",
"fieldB": "B_val"
}
}
}
Example 2
type Inner struct {
A string `hummus:"innerchild.fieldA"`
B string `hummus:"innerchild.fieldB"`
}
input := struct {
C string `hummus:"fieldC"`
I []Inner `hummus:"inner"`
}{
C: "C_val",
I: []Inner{
{
A: "A_val1",
B: "B_val1",
},
{
A: "A_val2",
B: "B_val2",
},
},
}
outJSON, err := hummus.Marshal(input)
Gives us the following JSON:
{
"fieldC": "C_val",
"inner": [
{
"innerchild": {
"fieldA": "A_val1",
"fieldB": "B_val1"
}
},
{
"innerchild": {
"fieldA": "A_val2",
"fieldB": "B_val2"
}
}
]
}