monoculum / formam

a package for decode form's values into struct in Go
Apache License 2.0
190 stars 19 forks source link

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

Closed darigaaz closed 3 years ago

darigaaz commented 3 years ago

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?