diff --git a/pkg/apis/jaegertracing/v1/options.go b/pkg/apis/jaegertracing/v1/options.go index 68ee4d542..63c449950 100644 --- a/pkg/apis/jaegertracing/v1/options.go +++ b/pkg/apis/jaegertracing/v1/options.go @@ -1,6 +1,7 @@ package v1 import ( + "bytes" "encoding/json" "fmt" "strings" @@ -38,7 +39,11 @@ func (o *Options) Filter(prefix string) Options { // UnmarshalJSON implements an alternative parser for this field func (o *Options) UnmarshalJSON(b []byte) error { var entries map[string]interface{} - json.Unmarshal(b, &entries) + d := json.NewDecoder(bytes.NewReader(b)) + d.UseNumber() + if err := d.Decode(&entries); err != nil { + return err + } return o.parse(entries) } diff --git a/pkg/apis/jaegertracing/v1/options_test.go b/pkg/apis/jaegertracing/v1/options_test.go index 51d5c6b6c..9508eed6f 100644 --- a/pkg/apis/jaegertracing/v1/options_test.go +++ b/pkg/apis/jaegertracing/v1/options_test.go @@ -64,6 +64,34 @@ func TestMultipleSubValues(t *testing.T) { assert.Len(t, args, 3) } +func TestUnmarshalToArgs(t *testing.T) { + tests := []struct { + in string + args []string + err string + }{ + {in: `^`, err: "invalid character '^' looking for beginning of value"}, + { + in: `{"a": 5000000000, "b": 15.222, "c":true, "d": "foo"}`, + args: []string{"--a=5000000000", "--b=15.222", "--c=true", "--d=foo"}, + }, + } + for _, test := range tests { + opts := Options{} + err := opts.UnmarshalJSON([]byte(test.in)) + if test.err != "" { + assert.EqualError(t, err, test.err) + } else { + assert.NoError(t, err) + args := opts.ToArgs() + sort.SliceStable(args, func(i, j int) bool { + return args[i] < args[j] + }) + assert.Equal(t, test.args, args) + } + } +} + func TestMultipleSubValuesWithFilter(t *testing.T) { o := NewOptions(nil) o.UnmarshalJSON([]byte(`{"memory": {"max-traces": "50000"}, "es": {"server-urls": "http://elasticsearch:9200", "username": "elastic", "password": "changeme"}}`))