jsonapi icon indicating copy to clipboard operation
jsonapi copied to clipboard

Support for unmarshalling top-level links

Open mmikalsen opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. The package does not support unmarshalling top-level links, usually utilizes for pagination.

Describe the solution you'd like UnmarshalOption to export the links from top-level, which has been done with meta. for example:

body := `{"data":{"id":"1","type":"articles","attributes":{"title":"Hello World"}},"links":{"self":"foobar"}}`

type Article struct {
    ID    string `jsonapi:"primary,articles"`
    Title string `jsonapi:"attribute"        json:"title"`
}

var (
    a Article
    l jsonapi.Link
)

err := jsonapi.Unmarshal([]byte(body), &a, jsonapi.UnmarshalLinks(&l))
// l.self = "foobar"

Describe alternatives you've considered n/a

mmikalsen avatar Feb 08 '24 18:02 mmikalsen

Sorely missing this as a feature! Would love to see it implemented as described in the OP.

zx8 avatar May 21 '24 23:05 zx8

Thanks for the contribution! This feature is now supported as of v0.10.0

DQSevilla avatar Jul 31 '24 17:07 DQSevilla