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
Add option to omit null fields in fromJson constructor or define default values #74
Comments
@AlexanderJohr – FYI, going to look into this soon... Something we want for other things. @jakemac53 FYI |
+1 for an annotation, and possibly a warning if it sees a default value for a constructor parameter that it knows its going to overwrite with (possibly) null? |
Awesome! |
Published, @AlexanderJohr – let us know how it goes... |
@kevmoo Works just great! Now I can remove all those factory constructors which ensured my default values before. |
👍 |
In my projects, several of my classes inherits this class :
The idea is to store the date when the objet was created. Setting the default value with @jsonkey(defaultValue: ...) is not enought because if the object is created not from a json, it doens't get his default value... Any idea ? |
@Nico04 – this is tough. You could create get/set pairs with a private field and ignore |
But what if I need this behavior globally for all my serializable classes? |
@Nico04 – we're not going to run with this. It'd add a LOT of complexity to the generator to track this. We're trying to keep things reasonably simple, especially if there is a work-around. |
I'm a bit disapointed but I totally understand your argument. |
It seems that now the package has a defaultValue key. |
I think this can solve your problem //when the variable has the value that match with the ignore json will not be constructed! @jsonkey(ignore: null) |
Great Library. Finally something to replace Dartson with. However: When deserializing fields that aren't in the json, they will be written to the object as null. In Angular I then get errors like "boolean expression must not be null". I would like to keep the default values assigned to the fields instead of having those overwritten by null:
Or maybe setting the default value with an annotation would be useful.
The text was updated successfully, but these errors were encountered: