aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-06-17 16:51:34 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-06-17 16:51:34 +0200
commit9b0122bdcd5603746c2ec59d360d6dee1494ca7c (patch)
treeafc0e8230fbc7e856a900c9309ea13c0fbb3e5be
parent86e4094f8f31a1266ada670ab48599b55fb2c61c (diff)
downloadgo-gg-9b0122bdcd5603746c2ec59d360d6dee1494ca7c.tar.gz
columnar: fix handling of json:"-" fields
-rw-r--r--CHANGELOG.md6
-rw-r--r--columnar/columnar.go2
-rw-r--r--columnar/columnar_test.go20
3 files changed, 27 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e41b7c4..96f65a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,12 @@ SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
SPDX-License-Identifier: Apache-2.0
-->
+# v1.9.1 (TBD)
+
+Changes:
+
+- Fix columnar choking on structs with `json:"-"` fields.
+
# v1.9.0 (2026-06-04)
Changes:
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},
+ },
+ )
+}