From 1947fea11fff75b7d6977b488f6a09c166a3c055 Mon Sep 17 00:00:00 2001 From: Sam Woodard Date: Thu, 11 Oct 2018 09:04:55 -0700 Subject: [PATCH] wrote failing test for example so removing from docs --- README.md | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/README.md b/README.md index c599dd3..44b0541 100644 --- a/README.md +++ b/README.md @@ -343,37 +343,6 @@ func (post Post) JSONAPIRelationshipMeta(relation string) *Meta { } ``` -### Custom types - -If you need to support custom types (e.g. for custom time formats), you'll need to implement the json.Marshaler and json.Unmarshaler interfaces on the type. - -```go -// MyTimeFormat is a custom format I invented for fun -const MyTimeFormat = "The time is 15:04:05. The year is 2006, and it is day 2 of January." - -// MyTime is a custom type used to handle the custom time format -type MyTime struct { - time.Time -} - -// UnmarshalJSON to implement the json.Unmarshaler interface -func (m *MyTime) UnmarshalJSON(b []byte) error { - t, err := time.Parse(MyTimeFormat, string(b)) - if err != nil { - return err - } - - m.Time = t - - return nil -} - -// MarshalJSON to implement the json.Marshaler interface -func (m *MyTime) MarshalJSON() ([]byte, error) { - return json.Marshal(m.Time.Format(MyTimeFormat)) -} -``` - ### Errors This package also implements support for JSON API compatible `errors` payloads using the following types.