duke-git / lancet

A comprehensive, efficient, and reusable util function library of Go.

Home Page:https://www.golancet.cn/en/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

maputil.MapToStruct json标签中的omitempty会干扰转化

sharemeans opened this issue · comments

commented

[version] v2.3.0

getFieldNameByJsonTag方法直接拿json tag和name比较不严谨。

demo:


import (
	"fmt"

	"github.com/duke-git/lancet/v2/maputil"
)

type BaseInfo struct {
	CreateAt int64  `json:"createAt,omitempty"`
	UpdateAt int64  `json:"updateAt,omitempty"`
	Currency string `json:"currency,omitempty"`
}

func main() {
	a := map[string]any{
		"createAt": 1715322586990,
		"updateAt": 1715322587201,
		"currency": "USD",
	}
	b := &BaseInfo{}
	maputil.MapToStruct(a, b)
	fmt.Printf("%v\n", b)
}

v2.3.1版本已修复