bsed / gorilla

Automatically exported from code.google.com/p/gorilla
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[schema] Field of Foo for "type Foo uint" won't decode #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if aliased types could be parsed correctly. encoding/json 
seems to do this, but my foo isn't strong enough to figure out how to patch 
schema to do this. I've attached test cases, one works the other doesn't and 
hopefully explains the issue.

Original issue reported on code.google.com by n...@daaku.org on 25 Apr 2012 at 12:15

Attachments:

GoogleCodeExporter commented 9 years ago
We require a converter for any custom type. 

Not sure if we should do type switching for derived basic types; I will take a 
look at encoding/json, but for the type being, register a function:

    decoder.RegisterConverter(Foo(0), func(s string) { 
    if v, err := strconv.ParseUint(s, 10, 0); err == nil {
        return reflect.ValueOf(Foo(v))
    }
    return reflect.Value{}
    })

Original comment by rodrigo.moraes on 25 Apr 2012 at 7:24