Skip to content
New issue

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

Error "unsupported type; maybe include it the UnmarshalText interface or register it using custom type?" with map[string]*struct #42

Closed
darigaaz opened this issue Jan 30, 2021 · 0 comments · Fixed by #43

Comments

@darigaaz
Copy link
Contributor

Code to reproduce:

func TestMapToPtrStruct(t *testing.T) {
	s := struct {
		// pointer to struct
		M map[string]*struct {
			ID string
		}
	}{}

	vals := url.Values{
		"M[key].ID": []string{"M[key].ID"},
	}

	dec := formam.NewDecoder(nil)
	if err := dec.Decode(vals, &s); err != nil {
		t.Fatalf("error when decode %s", err)
	}

	if v, ok := s.M["key"]; !ok {
		t.Error("The key \"key\" in M does not exists")
	} else if v.ID != "M[key].ID" {
		t.Error("The value in key \"key\" of M is incorrect")
	}
}

Expected: no error
Actual: error when decode formam: unsupported type; maybe include it the UnmarshalText interface or register it using custom type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant