mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Merge pull request #200 from unravelin/master
Stdlib json handles embedded structs with json tags differently.
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ install:
|
||||
- go get github.com/ugorji/go/codec
|
||||
- go get github.com/pquerna/ffjson/fflib/v1
|
||||
- go get github.com/json-iterator/go
|
||||
- go get github.com/golang/lint/golint
|
||||
- go get golang.org/x/lint/golint
|
||||
|
||||
+4
-2
@@ -343,7 +343,8 @@ func getStructFields(t reflect.Type) ([]reflect.StructField, error) {
|
||||
var efields []reflect.StructField
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
if !f.Anonymous {
|
||||
tags := parseFieldTags(f)
|
||||
if !f.Anonymous || tags.name != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -362,7 +363,8 @@ func getStructFields(t reflect.Type) ([]reflect.StructField, error) {
|
||||
var fields []reflect.StructField
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
if f.Anonymous {
|
||||
tags := parseFieldTags(f)
|
||||
if f.Anonymous && tags.name == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -6,19 +6,25 @@ type EmbeddedType struct {
|
||||
Inner struct {
|
||||
EmbeddedInnerType
|
||||
}
|
||||
Field2 int
|
||||
Field2 int
|
||||
EmbeddedInnerType2 `json:"named"`
|
||||
}
|
||||
|
||||
type EmbeddedInnerType struct {
|
||||
Field1 int
|
||||
}
|
||||
|
||||
type EmbeddedInnerType2 struct {
|
||||
Field3 int
|
||||
}
|
||||
|
||||
var embeddedTypeValue EmbeddedType
|
||||
|
||||
func init() {
|
||||
embeddedTypeValue.Field1 = 1
|
||||
embeddedTypeValue.Field2 = 2
|
||||
embeddedTypeValue.Inner.Field1 = 3
|
||||
embeddedTypeValue.Field3 = 4
|
||||
}
|
||||
|
||||
var embeddedTypeValueString = `{"Inner":{"Field1":3},"Field2":2,"Field1":1}`
|
||||
var embeddedTypeValueString = `{"Inner":{"Field1":3},"Field2":2,"named":{"Field3":4},"Field1":1}`
|
||||
|
||||
Reference in New Issue
Block a user