update MarshalJSON example
@@ -467,11 +467,31 @@ func ExampleTime_EndOfYear() {
}
func ExampleTime_MarshalJSON() {
- gt1 := gtime.New("2018-08-08 08:08:08")
+ type Person struct {
+ Name string `json:"name"`
+ Birthday *gtime.Time `json:"birthday"`
+ }
+ p := new(Person)
+ p.Name = "goframe"
+ p.Birthday = gtime.New("2018-08-08 08:08:08")
+ j, _ := json.Marshal(p)
+ fmt.Println(string(j))
+
+ // Output:
+ // {"name":"xiaoming","birthday":"2018-08-08 08:08:08"}
+}
- json, _ := gt1.MarshalJSON()
- fmt.Println(string(json))
+func ExampleTime_UnmarshalJSON() {
+ type Person struct {
+ Name string `json:"name"`
+ Birthday *gtime.Time `json:"birthday"`
+ }
+ p := new(Person)
+ src := `{"name":"goframe","birthday":"2018-08-08 08:08:08"}`
+ json.Unmarshal([]byte(src), p)
+ js, _ := json.Marshal(p)
+ fmt.Println(string(js))
// Output:
- // "2018-08-08 08:08:08"
+ // {"name":"goframe","birthday":"2018-08-08 08:08:08"}
}
