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
Describe the bug
Hi, recently started using your package and enjoy using it. I did unfortunately come across what seems to be a bug in fatih/structs, which ultimately ends up breaking some merge behavior for structs.Provider(). The tl;dr of the bug is that if you have a struct where all fields are default values, fatih/structs will think there was a problem representing the struct as a raw map and will leave the value in tact as the original struct value rather than turning it into map[string]any. The code that causes this can be found here.
Expected behavior
In the code above, the expected behavior is that the overrides don't change anything. The street value in the Address struct is empty, and so it should get dropped out because of omitempty, effectively meaning you're merging { "address": { } } into the existing value. Instead, fatih/structs leaves the Address struct value intact rather than converting it to map[string]any and dropping out the street field, causing the street value to get trampled by the empty value.
Please provide the following information):
OSX
GoLand
Koanf v1.5.0
Additional context
In my company's codebase, I got around this issue by implementing a custom structs provider that does a json marshal and unmarshal into map[string]any.
The text was updated successfully, but these errors were encountered:
Hi @gheinrich-dd. Apologies for the delayed reply. fatih/structs is frozen, so there is no possibility of getting a fix in. Perhaps a solution here is to use JSON marshalling to get a map[string]interface{} and to merge that into koanf directly without using the structs package. In fact, the structs provider could do this internally and get rid of fatih/structs.
Describe the bug
Hi, recently started using your package and enjoy using it. I did unfortunately come across what seems to be a bug in
fatih/structs
, which ultimately ends up breaking some merge behavior forstructs.Provider()
. The tl;dr of the bug is that if you have a struct where all fields are default values,fatih/structs
will think there was a problem representing the struct as a raw map and will leave the value in tact as the original struct value rather than turning it intomap[string]any
. The code that causes this can be found here.To Reproduce
Expected behavior
In the code above, the expected behavior is that the overrides don't change anything. The
street
value in theAddress
struct is empty, and so it should get dropped out because ofomitempty
, effectively meaning you're merging{ "address": { } }
into the existing value. Instead,fatih/structs
leaves theAddress
struct value intact rather than converting it tomap[string]any
and dropping out thestreet
field, causing thestreet
value to get trampled by the empty value.Please provide the following information):
Additional context
In my company's codebase, I got around this issue by implementing a custom structs provider that does a json marshal and unmarshal into
map[string]any
.The text was updated successfully, but these errors were encountered: