You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
I've come across and issue where when trying to convert a Gorm Model, which has a field of gorm.io/datatypes/JSON, and a value similar to ["a", "b", "c"].
It looks as though the assignment of the fieldType variable on line 1310 of mapstructure.go using reflection is incorrectly returning an integer type, and not a string. Given the ability to have json arrays with [1, "2"] - it might be better just to allow for a an interface{} when looking at arrays/json?
The resultant output is
2022/10/07 10:49:49 Unable to decode MyObject object: 5 error(s) decoding:
* 'my_field[0]' expected type 'uint8', got unconvertible type 'string', value: 'a'
* 'my_field[1]' expected type 'uint8', got unconvertible type 'string', value: 'b'
* 'my_field[2]' expected type 'uint8', got unconvertible type 'string', value: 'c'
Example Gorm Model
type Video struct {
ID uint `gorm:"primaryKey; type:bigint; not null;" json:"id"`
MyField datatypes.JSON `gorm:"type:jsonb;default:'[]';" json:"my_field" mapstructure:"my_field"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
All the best,
Ally
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello,
I've come across and issue where when trying to convert a Gorm Model, which has a field of
gorm.io/datatypes/JSON
, and a value similar to["a", "b", "c"]
.It looks as though the assignment of the fieldType variable on line 1310 of
mapstructure.go
using reflection is incorrectly returning an integer type, and not a string. Given the ability to have json arrays with [1, "2"] - it might be better just to allow for a an interface{} when looking at arrays/json?The resultant output is
Example Gorm Model
All the best,
Ally
The text was updated successfully, but these errors were encountered: