From 912abb484852bd26444c8af8ec3f64c1ff45b695 Mon Sep 17 00:00:00 2001 From: JinChang Date: Fri, 20 May 2022 09:10:13 +0800 Subject: [PATCH] Added ability to configure protojson (#1993) --- config/value.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/config/value.go b/config/value.go index d31bd86a4..04c1c0ebe 100644 --- a/config/value.go +++ b/config/value.go @@ -1,15 +1,16 @@ package config import ( - "encoding/json" + stdjson "encoding/json" "fmt" "reflect" "strconv" "sync/atomic" "time" - "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" + + "github.com/go-kratos/kratos/v2/encoding/json" ) var ( @@ -128,14 +129,14 @@ func (v *atomicValue) Duration() (time.Duration, error) { } func (v *atomicValue) Scan(obj interface{}) error { - data, err := json.Marshal(v.Load()) + data, err := stdjson.Marshal(v.Load()) if err != nil { return err } if pb, ok := obj.(proto.Message); ok { - return protojson.Unmarshal(data, pb) + return json.UnmarshalOptions.Unmarshal(data, pb) } - return json.Unmarshal(data, obj) + return stdjson.Unmarshal(data, obj) } type errValue struct {