Skip to content

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

@darigaaz

Description

@darigaaz

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions