diff options
Diffstat (limited to 'columnar')
| -rw-r--r-- | columnar/columnar.go | 2 | ||||
| -rw-r--r-- | columnar/columnar_test.go | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/columnar/columnar.go b/columnar/columnar.go index bb549f8..5e339ab 100644 --- a/columnar/columnar.go +++ b/columnar/columnar.go @@ -59,7 +59,7 @@ type List[T any] []T func foreachRelevantField(t reflect.Type, action func(f reflect.StructField)) { for idx := range t.NumField() { f := t.Field(idx) - if f.PkgPath == "" { + if f.PkgPath == "" && f.Tag.Get("json") != "-" { action(f) } } diff --git a/columnar/columnar_test.go b/columnar/columnar_test.go index 17dc964..70e27c4 100644 --- a/columnar/columnar_test.go +++ b/columnar/columnar_test.go @@ -116,3 +116,23 @@ func TestJSONUnmarshalFromInconsistentLengths(t *testing.T) { err := json.Unmarshal([]byte(`{"Foo":[1,2],"Bar":[3,4,5]}`), PointerTo(columnar.List[Record]{})) AssertEqual(t, err.Error(), `cannot unmarshal from columns with inconsistent lengths [2 3]`) } + +func TestIgnoredFields(t *testing.T) { + type Record struct { + Foo int `json:"foo"` + Bonus int `json:"-"` + } + + // There used to be a bug where columnar got confused that the `Bonus` field + // ends up as a zero-length array after unmarshaling. + testSuccessfulJSONRoundtrip(t, + []Record{ + {Foo: 1, Bonus: 0}, + {Foo: 2, Bonus: 0}, + {Foo: 3, Bonus: 0}, + }, + jsonmatch.Object{ + "foo": jsonmatch.Array{1, 2, 3}, + }, + ) +} |
