-
Notifications
You must be signed in to change notification settings - Fork 46
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
Default empty Arrays #22
Comments
Why not simply use |
😱 nononooooonoo. Especially in decoding you don't want your parser to make these implicit assumptions. One common situation I can think of is an API call querying a collection. Now (1) null might mean the collection didn't exist, whereas (2) an empty Array means it's empty. That's a very different thing though. 1) means a programmer error, and 2) means the user should populate it with some data. Don't surprise me with dynamic coercing behaviour. I can always throw in a |
I think in this case, having readJSON read from an input and then applying a series of e.g.
or something like that? |
Probably works if you only use NonEmpty Array everywhere, but not entirely sure if that's what you want in your codebase either |
@jacereda Sorry, only referring to deserialization. You're probably right.. unfortunately C# is really loose with nullability so I have a bunch of apis to work with which like to leave off arrays when they're empty, so I'll probably need to write custom |
Gist example for those reading this thread later: https://gist.github.com/justinwoo/9d0bb67a84c227f327da7171bb7105c2 |
Is the |
the |
Seems clear enough.. are you suggesting it shouldn't be used or might be removed? |
Yeah, mostly just shouldn't be used unless you're willing to lock down versions of simple-json (which is the easy part if you use psc-package I guess) and read all the release notes to make sure the behavior wasn't changed again |
What do you think about using
[]
as a "default" array value and allowing the key to be missing when parsing? (or maybe evenempty
ormempty
for any valid types)Not sure if this has drawbacks I'm not thinking of, but it'd sure be nice to get rid of a bunch of my
Maybe (Array a)
fields.Nothing
and[]
are kind of the same thing 🙂The text was updated successfully, but these errors were encountered: