From ad332368d89425279cc144203446b6577472af6b Mon Sep 17 00:00:00 2001 From: pd_pranay Date: Sun, 15 Aug 2021 20:37:14 +0530 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9D=20Update:=20Add=20JSONDecoder?= =?UTF-8?q?=20to=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app.go b/app.go index 5c555aa4a4..4f6b1856f7 100644 --- a/app.go +++ b/app.go @@ -308,6 +308,13 @@ type Config struct { // Default: json.Marshal JSONEncoder utils.JSONMarshal `json:"-"` + // When set by an external client of Fiber it will use the provided implementation of a + // JSONUnmarshal + // + // Allowing for flexibility in using another json library for encoding + // Default: json.Unmarshal + JSONDecoder utils.JSONUnmarshal `json:"-"` + // Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only) // WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chose. // @@ -459,6 +466,9 @@ func New(config ...Config) *App { if app.config.JSONEncoder == nil { app.config.JSONEncoder = json.Marshal } + if app.config.JSONDecoder == nil { + app.config.JSONDecoder = json.Unmarshal + } if app.config.Network == "" { app.config.Network = NetworkTCP4 } From da0ab127bf7e42eb99cafa00cb9bbdf212701304 Mon Sep 17 00:00:00 2001 From: pd_pranay Date: Wed, 18 Aug 2021 16:59:14 +0530 Subject: [PATCH 2/2] Update use config's json decoder method --- ctx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctx.go b/ctx.go index a3cc4b98ff..ec3a11eee6 100644 --- a/ctx.go +++ b/ctx.go @@ -291,7 +291,7 @@ func (c *Ctx) BodyParser(out interface{}) error { // Parse body accordingly if strings.HasPrefix(ctype, MIMEApplicationJSON) { schemaDecoder.SetAliasTag("json") - return json.Unmarshal(c.Body(), out) + return c.app.config.JSONDecoder(c.Body(), out) } if strings.HasPrefix(ctype, MIMEApplicationForm) { schemaDecoder.SetAliasTag("form")