1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

#67 time as int64

This commit is contained in:
Tao Wen
2017-06-20 17:43:47 +08:00
parent ed79b1726e
commit 486534c67c
11 changed files with 77 additions and 34 deletions

View File

@ -139,18 +139,18 @@ func Test_customize_field_by_extension(t *testing.T) {
type timeImplementedMarshaler time.Time
func (obj *timeImplementedMarshaler) MarshalJSON() ([]byte, error) {
seconds := time.Time(*obj).Unix()
func (obj timeImplementedMarshaler) MarshalJSON() ([]byte, error) {
seconds := time.Time(obj).Unix()
return []byte(strconv.FormatInt(seconds, 10)), nil
}
func Test_marshaler(t *testing.T) {
type TestObject struct {
Field *timeImplementedMarshaler
Field timeImplementedMarshaler
}
should := require.New(t)
val := timeImplementedMarshaler(time.Unix(123, 0))
obj := TestObject{&val}
obj := TestObject{val}
bytes, err := json.Marshal(obj)
should.Nil(err)
should.Equal(`{"Field":123}`, string(bytes))