Skip to content
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

nil handling #42

Closed
mweibel opened this issue May 9, 2023 · 9 comments
Closed

nil handling #42

mweibel opened this issue May 9, 2023 · 9 comments

Comments

@mweibel
Copy link
Collaborator

mweibel commented May 9, 2023

pinging @lombare @simaotwx @TorbenCK @mandeepji

We have several conflicting opinions about how to handle nil and/or empty maps/slices:
see the following PRs:

I accidentally merged again something which was previously called a regression just before (sorry about that); will revert that change.

What is your opinion on how this should be handled? Would we need additional flags to capture this?
Just a new version (github.com/liip/sheriff/v1) to make sure there aren't regressions in existing codebases?

Please let me know your thoughts. Thanks.

@TorbenCK
Copy link
Contributor

TorbenCK commented May 9, 2023

Yes, the change might be small, but might not be minor. It would lead to a regression, if a client expects that arrays are never null.

It is the same issue that we have, but reversed. We want to use sheriff but want to ensure that clients receive the same response as with json.Marshal.

I think a new version would be good

@TorbenCK
Copy link
Contributor

TorbenCK commented May 9, 2023

Another solution would be to make sheriff configurable. By default it will have the old behaviour, but the json.Marshal conform behaviour can be activated over configuration.

This should also cover the other issues you mentioned. Maybe it would also make sense to add a test case, that runs json.Marshal vs. sheriff.Marshal, to really exclude further differences.

What do you think?

@lombare
Copy link

lombare commented May 10, 2023

I agree with TorbenCK, the V2 sounds like a good idea since it won't break existing codebases

To feed the debate, I think that the good behavior is to have the same as json.Marshal (since his sole goal is to comply with the RFC)
To me the role of the Marshaler is to make a representation of a data, so if given null, then outs null and not {} or [].

@TorbenCK
Copy link
Contributor

Just wanted to follow-up as we are interested in a near-term solution for the problem. Can we release #43 soon?

@mandeepji
Copy link
Contributor

@mweibel May I know what is next step? Are we waiting for any changes/feedback or planning to merge #43 ?

@mweibel
Copy link
Collaborator Author

mweibel commented May 30, 2023

I read all the comments and will work on it as soon as I find the time to do so. I hope I find some time this week but can't guarantee it. In the meantime, you could work on a PR if you wish to do so (and use it using the replace directive of Go modules).

@TorbenCK
Copy link
Contributor

just wanted to follow-up. I am not sure what still needs to be done but hope someone will find time soon, so we can utilize this lib in our solution :)

@mweibel
Copy link
Collaborator Author

mweibel commented Mar 6, 2024

I released github.com/liip/sheriff/v2 in version v2.0.0-beta.1 just now. Sorry about the delay!

Had to bump it to v2 directly (instead of making a v1 first) because v0 and v1 are somehow synonymous. Not sure why but go modules are sometimes still a mystery to me ;)

Let me know how that goes, I intentionally released it as beta so we can still make changes if necessary.

@mweibel mweibel closed this as completed Mar 6, 2024
@mweibel
Copy link
Collaborator Author

mweibel commented Mar 6, 2024

ah yeah FTR, I didn't opt for options to control this behaviour. I believe this is too complicated. We should just strive to do whatever json.Marshal does IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants