Skip to content
New issue

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

[undefined] serde with a wrapper type for unserded type #491

Closed
liuq19 opened this issue Jul 31, 2023 · 0 comments · Fixed by #757
Closed

[undefined] serde with a wrapper type for unserded type #491

liuq19 opened this issue Jul 31, 2023 · 0 comments · Fixed by #757
Assignees
Labels
known-issue This issue is known to us, we are working on it

Comments

@liuq19
Copy link
Collaborator

liuq19 commented Jul 31, 2023

package issue_test

import (
	"encoding/json"
	"testing"

	"github.com/bytedance/sonic"
	"github.com/davecgh/go-spew/spew"
	"github.com/stretchr/testify/require"
)

type Function = func()

func MockFunc() {

}

type Unable struct {
	Functions []Function
}

type StructWithUnable struct {
	Foo *Unable
}

func TestMarshalWrapperUnable(t *testing.T) {
	// Wrapper a unbale serde type
	tests := []interface{} {
		map[string]*Function{},
		[]Function{},
		struct {
			Foo *Function
		}{},
	}
	for _, v := range(tests) {
		sout, serr := sonic.Marshal(&v)
		jout, jerr := json.Marshal(&v)
		require.Equal(t, serr, jerr, v)
		require.Equal(t, sout, jout, v)
	}
}

 func TestRule(t *testing.T) {
	type Test struct {
		data string
		value interface{}
	}

	tests := []Test{
		Test {
			data: "null",
			value: new([]Function),
		},
		Test {
			data: "[null, null]",
			value: new([]Function),
		},
		Test {
			data: "{\"foo\": null}",
			value: new(struct {
				Foo *Function
			}),
		},
	}
	for _, v := range(tests) {
		spew.Dump(v)
		jerr := json.Unmarshal([]byte(v.data), &v.value)
		require.NoError(t, jerr)
		serr := sonic.Unmarshal([]byte(v.data), &v.value)
		require.NoError(t, serr)
	}
 }
 
@liuq19 liuq19 changed the title unmarshal/marshal with a wrapper type for unserded type serde with a wrapper type for unserded type Jul 31, 2023
@liuq19 liuq19 changed the title serde with a wrapper type for unserded type [undefined] serde with a wrapper type for unserded type Aug 2, 2023
@liuq19 liuq19 added the known-issue This issue is known to us, we are working on it label Aug 2, 2023
@liuq19 liuq19 self-assigned this Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
known-issue This issue is known to us, we are working on it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant