You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	#67 time as int64
This commit is contained in:
		| @@ -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)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user