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
Make JsonKey's defaultValue a Function? type #1185
Comments
You know what I COULD do. We could allow |
Not a priority for me, but I'd accept a reasonable PR. |
I'm looking into the code and perhaps point me in the right direction if you have an idea already? If i try to pass a function expression to the current
The Were you thinking of changing the type of |
@erf – you will ONLY be able to pass in top-level or static functions. No instance functions will be allowed. |
@kevmoo that seem to work now - so not sure how to improve this per now. I'm closing this. Feel free to open this if you have any suggestions for further improvement. |
@erf – like...the feature actually works? I don't remember adding that feature. (goes to look at code...) |
This is NOT implemented. Build will break if you use a function. I actually have a todo here for this! |
Update docs in json_annotation Prepare to release json_serializable v6.5.0 Closes #1185
Sorry, i did not test it well, i just did not get any errors, i guess i misunderstood. It seems like you've fixed it now? Great stuff! I tried to pull down a local version now and link to it using |
Update docs in json_annotation Prepare to release json_serializable v6.5.0 Closes #1185
@kevmoo - when do you plan the release? |
Hopefully today!
…On Wed, Oct 5, 2022 at 2:54 PM Kamil ***@***.***> wrote:
@kevmoo <https://github.com/kevmoo> - when do you plan the release?
—
Reply to this email directly, view it on GitHub
<#1185 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEFCQXJPKKICTZI3F2YBLWBX2H5ANCNFSM56FYUIPA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Done! v6.5.0 |
Are you able to pass a function which returns a |
You just need to use a top-level or static function. |
Always good to share source code... |
I tried the following:
I also tried:
The last one produces:
Here the "The left operand can't be null, so the right operand is never executed. It also seem strange that |
Remove the |
Hrm...I'm digging now and seeing the problem. Will have to investigate. |
Will need to follow-up here: #1219 |
Ok. I was thinking if i kept the date values optional / nullable, i did not have to set them at construction time and then if i write them to json or parse them and the value is null, then the default value is used, not sure if this is possible. When i think about it i could just make them non-nullable, and just make a custom constructor for these cases and set the date values there. |
@erf you actually FOUND A BUG!! It affects Well done! |
Fixed now and published @erf |
I would like to supply a
DateTime.now()
as adefaultValue
toJsonKey
, but as it's not aconst
it's not possible to add it, however if it was of typeFunction?
i could pass it a function which would return a value in the same way astoJson
andfromJson
, e.g.static DateTime newDate() => DateTime.now();
This would be a breaking change so not sure if it's feasible, but it would make the API more flexible perhaps?Dart SDK version: 2.17.6 (stable) (Tue Jul 12 12:54:37 2022 +0200) on "macos_arm64"
The text was updated successfully, but these errors were encountered: