-
Notifications
You must be signed in to change notification settings - Fork 4
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
Modify code to allow :initform to be used for unspecified fields. #2
base: master
Are you sure you want to change the base?
Conversation
When specifying a class slot, we're allowed to pass an :initform specifying a form to use as the initial value of the slot when it's not passed to the constructor. Currently, if we we specify a slot with jeison-defclass, the behavior is to require that field be present in the decoded json. This is a problem for situations where fields may have a default value, but that default isn't necessarily encoded in the payload (eg: gRPC). Thus we change the default behavior to allow fields to not be present. This is a two part fix: 1) modify jeison--read-internal to allow null fields to skip type check 2) modify jeison--read-slot to return nil when a slot value is null Then, when jeison--read-class applies the constructor to initialization values, the unspecified fields will be absent and the constructor will use their :initform instead.
Any thoughts on merging this? |
I ran into this and would love to see it fixed. |
Sadly this repo's had no commits for three years so I fear the worst :( |
@patrickt, @smcallis: It does look like this particular repo has hit a dead end. I'm going to fork it -- I added support for a Are there any other enhancements you'd like to see? |
Nope mostly compatibility with gRPC was what I was after, so default values is all I need. |
Hi there folks, sorry I got out of my hibernation :) As part of the consideration, maybe we can make this behaviour optional? Like mark a slot that it might be absent in the actual JSON and that some other value should be used in that situation. |
@bscottm Hey, I see you worked a bit on your own fork. Sorry for being so unresponsive. |
@SavchenkoValeriy: I incorporated this pull request into my fork, so you can effectively ignore this one. |
When specifying a class slot, we're allowed to pass an :initform
specifying a form to use as the initial value of the slot when it's
not passed to the constructor.
Currently, if we we specify a slot with jeison-defclass, the behavior
is to require that field be present in the decoded json. This is a
problem for situations where fields may have a default value, but that
default isn't necessarily encoded in the payload (eg: gRPC). Thus we
change the default behavior to allow fields to not be present.
This is a two part fix:
Then, when jeison--read-class applies the constructor to initialization
values, the unspecified fields will be absent and the constructor will
use their :initform instead.