Skip to content

Commit

Permalink
Handle json tag without name override
Browse files Browse the repository at this point in the history
  • Loading branch information
matevzmihalic committed Jan 21, 2025
1 parent f6fea90 commit 22edb2a
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 22edb2a

Please sign in to comment.