mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
merge
This commit is contained in:
commit
ccb972f58c
@ -1058,12 +1058,12 @@ func (encoder *structEncoder) encode(ptr unsafe.Pointer, stream *Stream) {
|
|||||||
stream.WriteObjectStart()
|
stream.WriteObjectStart()
|
||||||
isNotFirst := false
|
isNotFirst := false
|
||||||
for _, field := range encoder.fields {
|
for _, field := range encoder.fields {
|
||||||
if isNotFirst {
|
|
||||||
stream.WriteMore()
|
|
||||||
}
|
|
||||||
if field.omitempty && field.isEmpty(ptr) {
|
if field.omitempty && field.isEmpty(ptr) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if isNotFirst {
|
||||||
|
stream.WriteMore()
|
||||||
|
}
|
||||||
field.encode(ptr, stream)
|
field.encode(ptr, stream)
|
||||||
isNotFirst = true
|
isNotFirst = true
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,7 @@ func Test_omit_empty(t *testing.T) {
|
|||||||
type TestObject struct {
|
type TestObject struct {
|
||||||
Field1 string `json:"field-1,omitempty"`
|
Field1 string `json:"field-1,omitempty"`
|
||||||
Field2 string `json:"field-2,omitempty"`
|
Field2 string `json:"field-2,omitempty"`
|
||||||
|
Field3 string `json:"field-3,omitempty"`
|
||||||
}
|
}
|
||||||
obj := TestObject{}
|
obj := TestObject{}
|
||||||
obj.Field2 = "hello"
|
obj.Field2 = "hello"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user