Skip to content

Support marshal json#16

Closed
abusizhishen wants to merge 5 commits intoelliotchance:masterfrom
abusizhishen:support_marshal_json
Closed

Support marshal json#16
abusizhishen wants to merge 5 commits intoelliotchance:masterfrom
abusizhishen:support_marshal_json

Conversation

@abusizhishen
Copy link
Copy Markdown

@abusizhishen abusizhishen commented Jul 4, 2020

This change is Reviewable

orderedmap.go Outdated
}
}

type Item [2]interface{}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be part of the public API and you will need to provide tests with your code for it to be accepted. Also, please use go fmt.

m := orderedmap.NewOrderedMap()
m.Set(1, 1)
b, err := json.Marshal(m)
result := bytes.Equal([]byte(`[1,1]`), b) && nil == err
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very opinionated way to serialize that I don't think is suitable for general use. If I remember correctly, I did not include JSON support in orderedmap because serialization is ambiguous (since maps aren't always ordered).

If you need to serialize in this specific format you should create an alias type. I cannot accept this patch, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants