Skip to content

Commit

Permalink
Merge pull request #1478 from matevzmihalic/fix-json-tag
Browse files Browse the repository at this point in the history
Handle json tag without name override
  • Loading branch information
SpencerTorres authored Jan 21, 2025
2 parents f6fea90 + 22edb2a commit 1195999
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions examples/clickhouse_api/json_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
)

type ProductPricing struct {
Price int64 `json:"price"`
Currency string `json:"currency"`
Price int64 `json:",omitempty"`
Currency string `json:",omitempty"`
}

type Product struct {
Expand Down
4 changes: 2 additions & 2 deletions lib/column/json_reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *JSON) fillStruct(val reflect.Value, prefix string, row int) error {
}

name := fieldType.Tag.Get("json")
if name == "" {
if name == "" || name[0] == ',' {
name = fieldType.Name
} else {
name = strings.Split(name, ",")[0]
Expand Down Expand Up @@ -311,7 +311,7 @@ func iterateStruct(val reflect.Value, prefix string, json *chcol.JSON) error {
}

name := fieldType.Tag.Get("json")
if name == "" {
if name == "" || name[0] == ',' {
name = fieldType.Name
} else {
// handle `json:"name,omitempty"`
Expand Down

0 comments on commit 1195999

Please sign in to comment.