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

Private fields bugs when renaming #260

Closed
gobigshark opened this issue Apr 10, 2018 · 2 comments
Closed

Private fields bugs when renaming #260

gobigshark opened this issue Apr 10, 2018 · 2 comments

Comments

@gobigshark
Copy link

gobigshark commented Apr 10, 2018

Failed to support private fields when renaming.

`package main

import (
"fmt"

jsoniter "github.com/json-iterator/go"
"github.com/json-iterator/go/extra"

)

func main() {
extra.SupportPrivateFields()
type TestObject struct {
field string json:"myfield"
}
obj := TestObject{}
jsoniter.UnmarshalFromString({"myfield":"Hello"}, &obj)
fmt.Println(obj.field) // Output empty string instead of "Hello"
}`

@ceshihao
Copy link
Contributor

It is because your field field is unexported. It is introduced by #175

@taowen said

if field is unexported, the field names will be empty slice. field names are used to decode or encode one go field from multiple json field. if is empty, meaning it is not present in json.

I am wondering whether unexported field need to be support if using the private field extension?

@taowen taowen closed this as completed in f246f80 Apr 18, 2018
@yuyistudio
Copy link

I thought extra.SupportPrivateFields() meant that the export of private fields were fully supported. Still don't get the idea why the rename of private fields are designed to be forbidden, which means lower-camel-case style is now a unpleasant compulsion for all exported JSON data of my program.

zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
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

No branches or pull requests

3 participants