martini-contrib / binding

Martini handler for mapping and validating a raw request into a structure.
MIT License
140 stars 45 forks source link

binding bug #20

Closed easykoo closed 10 years ago

easykoo commented 10 years ago

when struct has a struct field, it will miss values

mholt commented 10 years ago

Hi @easykoo. Can you provide more information and a case to reproduce this?

easykoo commented 10 years ago

Thanks, @mholt. I found the root cause, the two structs has the same field named 'id'. I think I just need to change the form name.

type Role struct {
    Id          int    `form:"id"` //should change to 'roleId'
    Description string `form:"description"`
}

type User struct {
    Id       int    `form:"id"`
    Username string `form:"username"`
    Role     Role   `json:"role_id"`
}
mholt commented 10 years ago

Ah, yes, that's probably because form bodies have a flat structure, so if field names overlap, the deserializer gets confused. Glad you figured it out!