Commit 9d087a72 authored by whyrusleeping's avatar whyrusleeping

add json marshalers to CborTime

parent 0eaa2b53
......@@ -2,6 +2,7 @@ package testing
import (
"bytes"
"encoding/json"
"math/rand"
"reflect"
"testing"
......@@ -146,4 +147,18 @@ func TestTimeIsh(t *testing.T) {
t.Fatal("no")
}
b, err := json.Marshal(val)
if err != nil {
t.Fatal(err)
}
var out2 ThingWithSomeTime
if err := json.Unmarshal(b, &out2); err != nil {
t.Fatal(err)
}
if out2.When != out.When {
t.Fatal(err)
}
}
......@@ -739,3 +739,16 @@ func (ct *CborTime) UnmarshalCBOR(r io.Reader) error {
func (ct CborTime) Time() time.Time {
return (time.Time)(ct)
}
func (ct CborTime) MarshalJSON() ([]byte, error) {
return ct.Time().MarshalJSON()
}
func (ct *CborTime) UnmarshalJSON(b []byte) error {
var t time.Time
if err := t.UnmarshalJSON(b); err != nil {
return err
}
*(*time.Time)(ct) = t
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment