-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent flattening behaviour for empty slices in structs #331
base: v4
Are you sure you want to change the base?
Conversation
Hi @dokterbob , I'm afraid that in its current state this PR isn't a change I'd like to make to radix. The mapping of an empty array to an empty string is not something I think others would find to be obvious, and would probably lead to someone accidentally setting an empty string into their dataset without realizing it. Honestly I think the better strategy might be (though I haven't put a ton of thought into it) to have As for |
Hi @mediocregopher, Thanks for the feedback! Let me try and reflect this so we're both sure we're talking about the same thing. Currently a struct containing a slice (e.g. You are suggesting to have radix return an error when an empty slice is flattened. However, this excludes the possibility of setting an empty value, e.g. when we intentionally want to store an empty slice In addition, having the Whatever the outcome, I would suggest explicitly documenting this in I am working on some more issues getting radix v4 to work. Depending on how that goes I might be able to update the PR as per the outcome of this conversation. |
I am suggesting that radix should return an error whenever any slice which is the value of a struct (or map) field is being flattened. For example:
You can see in the last example that, even ignoring the question of empty slices, it's very possible to get into situations where the flattened form becomes ambiguous if the value of a struct field is a slice. So this is why I suggest that Flattening structs with slice/map fields should just be disallowed completely, as it forces users to go another route which is less ambiguous (such as writing their own resp (un)marshalers, or encoding to JSON). |
Test demonstrating #330 and a proposed solution to it consistent with (and copied/borrowed from) Go's own
encoding/json
package:""
.omitempty
is used, the field will be not be present at all.Regrettably, I found the code in
marshal_unmarshal_test.go
inaccessible. To respect my time and sanity and as a suggestion to the maintainer ofradix
, not withstanding my gratitude to them for a great library, I have created a separate testify test suite for theFlatten()
function.