DataDog / jsonapi

A marshaler/unmarshaler for JSON:API.
Apache License 2.0
62 stars 9 forks source link

Support for unmarshalling top-level links #51

Closed mmikalsen closed 2 months ago

mmikalsen commented 7 months ago

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

zx8 commented 4 months ago

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

DQSevilla commented 2 months ago

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