rescript-labs / decco

Bucklescript PPX which generates JSON (de)serializers for user-defined types
MIT License
227 stars 27 forks source link

change optionFromJson to enable it to handle undefined values #80

Closed adnelson closed 2 years ago

adnelson commented 2 years ago

Changes decco's optionFromJson so that it treats both null and undefined as None. This makes it much easier to deal with objects coming in from JS code which might use undefined or have the field missing entirely.

adnelson commented 2 years ago

I'm not sure why the CI failed, it looks like some of the jobs weren't run. If there's anything further you need from me on this PR please let me know.

ryb73 commented 2 years ago

Hi @adnelson. Thanks for the PR.

Not sure why CI failed, I'll have to take a look at that.

This change seems reasonable, I'm curious though if the [@decco.default] annotation would meet your use case?

adnelson commented 2 years ago

@ryb73 thanks for the response, I tried it but unfortunately I get an error if the field is set to undefined. It finds the key set on the object, then tries to parse it as null, which fails, since null !== undefined

adnelson commented 2 years ago

Just wondering is this ok to merge? Does the reasoning make sense?

adnelson commented 2 years ago

ryb73 commented 2 years ago

Hey @adnelson, sorry for the delay. I merged the PR but am unable to publish. You can see #82 for more info.

ryb73 commented 2 years ago

This change has been released in v1.6.0.