Skip to content

Conversation

peterlimg
Copy link
Contributor

Embed struct with tag does not have the key encoded, for example:

type Foo struct {
    Name string
}
type Bar struct {
	Foo `json:"foo"`
	ID  string `json:"id"`
}
func main() {
	b := Bar{ID:"abc"}
	v, err := json.Marshal(b)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(v))
}

The output will be {{"Name":""},"id":"abc"}, the key of foo is lost, which is different from the behavior of encoding/json.

This PR will fix this issue.

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2021

Codecov Report

Merging #265 (91e691a) into master (85a5597) will increase coverage by 0.23%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #265      +/-   ##
==========================================
+ Coverage   81.00%   81.24%   +0.23%     
==========================================
  Files          47       47              
  Lines       14828    15566     +738     
==========================================
+ Hits        12012    12646     +634     
- Misses       2262     2360      +98     
- Partials      554      560       +6     

`p` was not updated after the `stream.buf` is reallocated
@goccy
Copy link
Owner

goccy commented Aug 12, 2021

Thank you for the great PR !!! I appreciate it very much

@goccy goccy merged commit a1780c1 into goccy:master Aug 12, 2021
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.

3 participants