@@ -1578,7 +1578,6 @@ func TestGithubIssue41(t *testing.T) {
1578
1578
"expected: " , expectedString ,
1579
1579
)
1580
1580
}
1581
-
1582
1581
}
1583
1582
1584
1583
func TestGithubIssue44 (t * testing.T ) {
@@ -1602,6 +1601,40 @@ func (r *rawJsonString) UnmarshalJSON(b []byte) error {
1602
1601
return nil
1603
1602
}
1604
1603
1604
+ // See https://github.com/segmentio/encoding/issues/63
1605
+ // In short, embedding a struct pointer resulted in an incorrect memory address
1606
+ // as we were still looking to the parent struct to start and only using offsets
1607
+ // which resulted in the wrong values being extracted.
1608
+ func TestGithubIssue63 (t * testing.T ) {
1609
+ expectedString := `{"my_field":"test","my_other_field":"testing","code":1}`
1610
+
1611
+ type MyStruct struct {
1612
+ MyField string `json:"my_field,omitempty"`
1613
+ MyOtherField string `json:"my_other_field"`
1614
+ MyEmptyField string `json:"my_empty_field,omitempty"`
1615
+ }
1616
+
1617
+ type MyStruct2 struct {
1618
+ * MyStruct
1619
+ Code int `json:"code"`
1620
+ }
1621
+
1622
+ input := MyStruct2 {
1623
+ MyStruct : & MyStruct {
1624
+ MyField : "test" ,
1625
+ MyOtherField : "testing" ,
1626
+ },
1627
+ Code : 1 ,
1628
+ }
1629
+
1630
+ if b , err := Marshal (input ); err != nil {
1631
+ t .Error (err )
1632
+ } else if string (b ) != expectedString {
1633
+ t .Errorf ("got: %s" , string (b ))
1634
+ t .Errorf ("expected: %s" , expectedString )
1635
+ }
1636
+ }
1637
+
1605
1638
func TestSetTrustRawMessage (t * testing.T ) {
1606
1639
buf := & bytes.Buffer {}
1607
1640
enc := NewEncoder (buf )
0 commit comments