Skip to content

[Question] Form encoding/decoding ignores slice of struct #214

Description

@tommysalt

Current Behavior

When encoding/decoding from data with slices of custom structs, they are ignored even thought the examples mention:

[...]
struct
[...]
a slice or a pointer to a slice of one of the above types

Output:

map[name:[Name]]

Expected Behavior

Output:

map[name:[Name], id:[1 2], amount:[1 2]

Steps To Reproduce

var encoder = schema.NewEncoder()

type Position struct {
	ID     int64 `schema:"id"`
	Amount int64 `schema:"amount"`
}

type Document struct {
	Name      string     `schema:"name"`
	Positions []Position `schema:"position"`
}

func main() {
	person := Document{"Name", []Position{{1, 1}, {2, 2}}}
	form := url.Values{}

	encoder.Encode(person, form)

	fmt.Println(form)
}

Output:

map[name:[Name]]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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