We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json.Marshaler
,string
func TestIssue670_JSONMarshaler(t *testing.T) { var obj = Issue670JSONMarshaler{ D: Date(time.Now().Unix()) } so, _ := sonic.MarshalString(obj) eo, _ := json.Marshal(obj) assert.Equal(t, string(eo), so) println(string(eo)) } func TestIssue670_JSONUnmarshaler(t *testing.T) { // match eo := []byte(`{"D":"2021-08-26","E":1}`) et := reflect.TypeOf(Issue670JSONMarshaler{}) testUnmarshal(t, eo, et, true) // mismatch eo = []byte(`{"D":11,"E":1}`) testUnmarshal(t, eo, et, true) // null eo = []byte(`{"D":null,"E":1}`) testUnmarshal(t, eo, et, true) } func testUnmarshal(t *testing.T, eo []byte, rt reflect.Type, checkobj bool) { obj := reflect.New(rt).Interface() println(string(eo)) println("sonic") es := sonic.Unmarshal(eo, obj) obj2 := reflect.New(rt).Interface() println("std") ee := json.Unmarshal(eo, obj2) assert.Equal(t, ee ==nil, es == nil, es) if checkobj { assert.Equal(t, obj2, obj) } fmt.Printf("std: %v, obj: %#v", ee, obj2) fmt.Printf("sonic error: %v, obj: %#v", es, obj) }
Error: Not equal: expected: "{\"delivery_date\":\"2024-07-31\"}" actual : "{\"delivery_date\":\"\"2024-07-31\"\"}" Diff: --- Expected +++ Actual @@ -1 +1 @@ -{"delivery_date":"2024-07-31"} +{"delivery_date":""2024-07-31""} Error: Not equal: expected: true actual : false Test: TestIssue670_JSONUnmarshaler Messages: "Syntax error at index 10: invalid char\n\n\t{\"D\":\"2021-08-26\",\"E\":1}\n\t..........^.............\n" Error: Not equal: expected: &issue_test.Issue670JSONMarshaler{D:1629936000, E:1} actual : &issue_test.Issue670JSONMarshaler{D:2021, E:0} Diff: --- Expected +++ Actual @@ -1,4 +1,4 @@ (*issue_test.Issue670JSONMarshaler)({ - D: (issue_test.Date) 1629936000, - E: (int) 1 + D: (issue_test.Date) 2021, + E: (int) 0 }) Test: TestIssue670_JSONUnmarshaler Error: Not equal: expected: &issue_test.Issue670JSONMarshaler{D:0, E:1} actual : &issue_test.Issue670JSONMarshaler{D:0, E:0} Diff: --- Expected +++ Actual @@ -2,3 +2,3 @@ D: (issue_test.Date) 0, - E: (int) 1 + E: (int) 0 }) Test: TestIssue670_JSONUnmarshaler
The text was updated successfully, but these errors were encountered:
fixed by #682
Sorry, something went wrong.
No branches or pull requests
Reproducible codes
Result
Reason
json.Marshaler
fields, std didn't consider,string
tag (to quote), but sonic handle both (https://github.com/bytedance/sonic/blob/main/internal/encoder/compiler.go#L607)The text was updated successfully, but these errors were encountered: