From f1000e3be0ce1d221c08cebbe13e184414a092f6 Mon Sep 17 00:00:00 2001 From: Oleg Lobanov Date: Sat, 25 Apr 2020 11:46:16 +0200 Subject: [PATCH] Fix unmarshalling struct with custom json tag claim --- json_token.go | 1 + json_token_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/json_token.go b/json_token.go index 93be4d5..b589c09 100644 --- a/json_token.go +++ b/json_token.go @@ -110,6 +110,7 @@ func (t *JSONToken) Get(key string, v interface{}) error { decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ DecodeHook: decodeHook, Result: v, + TagName: "json", }) if err != nil { return errors.Errorf("failed to create map decoder: %w", err) diff --git a/json_token_test.go b/json_token_test.go index 6757a2d..be5f51b 100644 --- a/json_token_test.go +++ b/json_token_test.go @@ -41,7 +41,7 @@ func TestJsonToken(t *testing.T) { type CustomStruct struct { Foo string Bar int - StrInt StrInt + StrInt StrInt `json:"custom_field"` } var (