Skip to content

Commit

Permalink
rename SetJsonNumber to SetMarshalJsonNumbers
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra committed Jan 23, 2024
1 parent 6f8daf8 commit 7b5aa9f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/jsontoml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func convert(r io.Reader, w io.Writer) error {

if useNumber != nil && *useNumber {
d.UseNumber()
e.SetJsonNumber(true)
e.SetMarshalJsonNumbers(true)
}

err := d.Decode(&v)
Expand Down
18 changes: 9 additions & 9 deletions marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type Encoder struct {
w io.Writer

// global settings
tablesInline bool
arraysMultiline bool
indentSymbol string
indentTables bool
jsonNumber bool
tablesInline bool
arraysMultiline bool
indentSymbol string
indentTables bool
marshalJsonNumbers bool
}

// NewEncoder returns a new Encoder that writes to w.
Expand Down Expand Up @@ -89,10 +89,10 @@ func (enc *Encoder) SetIndentTables(indent bool) *Encoder {
return enc
}

// SetJsonNumber forces the encoder to serialize `json.Number` as a float or integer
// SetMarshalJsonNumbers forces the encoder to serialize `json.Number` as a float or integer
// instead of relying on TextMarshaler to emit a string.
func (enc *Encoder) SetJsonNumber(indent bool) *Encoder {
enc.jsonNumber = indent
func (enc *Encoder) SetMarshalJsonNumbers(indent bool) *Encoder {
enc.marshalJsonNumbers = indent
return enc
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func (enc *Encoder) encode(b []byte, ctx encoderCtx, v reflect.Value) ([]byte, e
case LocalDateTime:
return append(b, x.String()...), nil
case json.Number:
if enc.jsonNumber {
if enc.marshalJsonNumbers {
if x == "" { /// Useful zero value.
return append(b, "0"...), nil
} else if v, err := x.Int64(); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ func TestEncoderSetIndentSymbol(t *testing.T) {
func TestEncoderSetJsonNumber(t *testing.T) {
var w strings.Builder
enc := toml.NewEncoder(&w)
enc.SetJsonNumber(true)
enc.SetMarshalJsonNumbers(true)
err := enc.Encode(map[string]interface{}{
"A": json.Number("1.1"),
"B": json.Number("42e-3"),
Expand Down

0 comments on commit 7b5aa9f

Please sign in to comment.