google / jsonapi

jsonapi.org style payload serializer and deserializer
http://godoc.org/github.com/google/jsonapi
MIT License
1.42k stars 210 forks source link

Add support for meta annotations on model fields #183

Closed codyaray closed 1 year ago

codyaray commented 4 years ago

Instead of using the JSONAPIMeta() hook, allow specifying metadata directly in the model/node.

type Blog struct {
    ID              int       `jsonapi:"primary,blogs"`
    Title           string    `jsonapi:"attr,title"`
    ModifiedAt      time.Time `jsonapi:"meta,modified_at"` // not iso 8601, serialize as epoch time
    DeletedAt       time.Time `jsonapi:"meta,deleted_at,iso8601"`
    ResourceVersion string    `jsonapi:"meta,resource_version"`
}

This supports epoch timestamps, iso8601 datetime strings, and other stringify-able data types.

googlebot commented 4 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.