Created
July 15, 2020 13:15
-
-
Save kendellfab/64788ad726ec18c2fd146883dc5bb35f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// KTTime is an example of a type that is aliased to time, than implements the json marshaling functions. | |
// This is an example for how to build serialization interopability with kotlin/gson. | |
package kttime | |
type KTTime time.Time | |
func (t KTTime) MarshalJSON() ([]byte, error) { | |
gt := time.Time(t) | |
f := gt.Format(ktFormat) | |
return json.Marshal(f) | |
} | |
func (t *KTTime) UnmarshalJSON(b []byte) error { | |
input := strings.Trim(string(b), `"`) | |
gt, err := time.Parse(ktFormat, input) | |
if err != nil { | |
return err | |
} | |
*t = KTTime(gt) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment