mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Merge pull request #168 from nsd20463/embedded_unnamed_types
Embedded unnamed types fix
This commit is contained in:
@@ -23,7 +23,8 @@ generate: root build
|
||||
.root/src/$(PKG)/tests/data.go \
|
||||
.root/src/$(PKG)/tests/omitempty.go \
|
||||
.root/src/$(PKG)/tests/nothing.go \
|
||||
.root/src/$(PKG)/tests/named_type.go
|
||||
.root/src/$(PKG)/tests/named_type.go \
|
||||
.root/src/$(PKG)/tests/embedded_type.go
|
||||
|
||||
.root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
|
||||
.root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
|
||||
@@ -33,6 +34,7 @@ generate: root build
|
||||
.root/bin/easyjson -build_tags=use_easyjson .root/src/$(PKG)/benchmark/data.go
|
||||
.root/bin/easyjson .root/src/$(PKG)/tests/nested_easy.go
|
||||
.root/bin/easyjson .root/src/$(PKG)/tests/named_type.go
|
||||
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
|
||||
|
||||
test: generate root
|
||||
go test \
|
||||
|
||||
+5
-1
@@ -284,7 +284,11 @@ func (g *Generator) getType(t reflect.Type) string {
|
||||
lines := make([]string, 0, nf)
|
||||
for i := 0; i < nf; i++ {
|
||||
f := t.Field(i)
|
||||
line := f.Name + " " + g.getType(f.Type)
|
||||
var line string
|
||||
if !f.Anonymous {
|
||||
line = f.Name + " "
|
||||
} // else the field is anonymous (an embedded type)
|
||||
line += g.getType(f.Type)
|
||||
t := f.Tag
|
||||
if t != "" {
|
||||
line += " " + escapeTag(t)
|
||||
|
||||
@@ -38,6 +38,7 @@ var testCases = []struct {
|
||||
{&IntsValue, IntsString},
|
||||
{&mapStringStringValue, mapStringStringString},
|
||||
{&namedTypeValue, namedTypeValueString},
|
||||
{&embeddedTypeValue, embeddedTypeValueString},
|
||||
{&mapMyIntStringValue, mapMyIntStringValueString},
|
||||
{&mapIntStringValue, mapIntStringValueString},
|
||||
{&mapInt32StringValue, mapInt32StringValueString},
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type EmbeddedType struct {
|
||||
EmbeddedInnerType
|
||||
Inner struct {
|
||||
EmbeddedInnerType
|
||||
}
|
||||
Field2 int
|
||||
}
|
||||
|
||||
type EmbeddedInnerType struct {
|
||||
Field1 int
|
||||
}
|
||||
|
||||
var embeddedTypeValue EmbeddedType
|
||||
|
||||
func init() {
|
||||
embeddedTypeValue.Field1 = 1
|
||||
embeddedTypeValue.Field2 = 2
|
||||
embeddedTypeValue.Inner.Field1 = 3
|
||||
}
|
||||
|
||||
var embeddedTypeValueString = `{"Inner":{"Field1":3},"Field2":2,"Field1":1}`
|
||||
Reference in New Issue
Block a user