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.
When decoding a struct containing a string pointer and a struct pointer into a map, the resulting map has a pointer to the string but not a pointer to the struct.
mapstructure version bf980b3
go version go1.18.7 linux/amd64
I can't see a reason why structures and base types should behave differently. I would expect to either keep the pointers or remove them. Can you please explain to me if this is a design choice or not? My guess is that struct pointers where not supported before PR #271 which made it dereference struct pointers systematically.
Discussion
Should all pointers be represented in the target map or none?
From the perspective of my use case, the pointer representation in the map is not necessary.
Here are the benefits of the pointers usage in this context:
Data representation : allows the representation of "no information". E.g. a nul pointer is different from an empty string.
-> nul pointer can be represented as an unset key
Memory and speed optimization : redundent data structures can be referenced and large data structure can be referenced so that they are not copied on return
-> this can be usefull when the decoded structure contains big data that should not be copied
For these reasons, I would suggest to:
Handle pointers of any type in the same way (e.g. struct pointers and string pointers)
Create a global option tho choose whether to keep or not the pointer representation in the target map (in the other direction, it's the type of the struct data that defines if it's a pointer or not). Defaults to "remove pointers". Name suggestion : "PreserveReferences"(true/false)
For retro-compatibility, add an option to keep the pointer representation on non-struct types. Eventually set this by default until next major. Name suggestion : "LegacyReferencesHandling" (true/false)
Add a property tag option to keep pointer representation and not copy data but only the pointer value (used for optimiazation in case of a large data structure, for example a string, that should be referenced in the map instead of copied). Name suggestion: "nocopy"
As an alternative, the options could be merge in a "ReferencesHandling" option with values legacy/preserve/discard.
Please let me know what you think and if there are any thechnical constraints that would not allow this. I would be happy to contribute.
The text was updated successfully, but these errors were encountered:
When decoding a struct containing a string pointer and a struct pointer into a map, the resulting map has a pointer to the string but not a pointer to the struct.
Produces:
mapstructure version bf980b3
go version go1.18.7 linux/amd64
I can't see a reason why structures and base types should behave differently. I would expect to either keep the pointers or remove them. Can you please explain to me if this is a design choice or not? My guess is that struct pointers where not supported before PR #271 which made it dereference struct pointers systematically.
Discussion
Should all pointers be represented in the target map or none?
From the perspective of my use case, the pointer representation in the map is not necessary.
Here are the benefits of the pointers usage in this context:
-> nul pointer can be represented as an unset key
-> this can be usefull when the decoded structure contains big data that should not be copied
For these reasons, I would suggest to:
As an alternative, the options could be merge in a "ReferencesHandling" option with values legacy/preserve/discard.
Please let me know what you think and if there are any thechnical constraints that would not allow this. I would be happy to contribute.
The text was updated successfully, but these errors were encountered: