Ignore null properties by default
See original GitHub issueEffectively default the behaviour of BsonIgnoreIfNull
on all properties. If I understand it correctly, there shouldn’t be any noticeable impact from this change besides less data in the DB.
More research may need to be done and asked about directly to MongoDB themselves.
Pros
- Less storage used by MongoDB
- Less data to send down the wire (AFAIK null properties are still sent - may depend on the driver)
Cons
- If you depend on
null
being saved (which is definitely possible), it obviously won’t which would break things. At minimum would need a way to opt-out of default ignoring ofnull
values - whether that is MongoFramework-wide or type-wide would still need to be determined.
Notes
- No known impact for querying performance in the DB because of ignored properties (eg. doesn’t seem to impact indexing)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Ignore Null Fields with Jackson
This quick tutorial is going to cover how to set up Jackson to ignore null fields when serializing a java class.
Read more >How to tell Jackson to ignore a field during serialization if ...
To omit all null values in the class as a default, annotate the class. Per-field/getter annotations can still be used to override this ......
Read more >3 ways to ignore null fields while converting Java object ...
You can ignore null fields at the class level by using @JsonInclude(Include.NON_NULL) to only include non-null fields, thus excluding any attribute whose value...
Read more >How to ignore properties with System.Text.Json
Learn how to ignore properties when serializing with System.Text. ... Ignore all null-value properties; Ignore all default-value properties ...
Read more >JsonSerializerOptions.IgnoreNullValues Property
Gets or sets a value that indicates whether null values are ignored during serialization and deserialization. The default value is false.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think making this optional will be more appropriate I have this case which will be impacted with such a decision I have made dynamic content which will be created dynamically using a dynamically created schema The fields may be required and may be nullable In case of nullable fields, I still need the key to be returned when returning the content to the front end so that the schema of a content stay somewhat consistence In case the ignore null by default was enforced, I will have to get also the schema and compare and attach any null field key to the returned object, which may be cumbersome in case of a paginated list of data Thank you
All good mate! It is the holidays for most of the world, you don’t need to get back to me instantly.
That sounds like a very interesting project. Is this part of an internal project or maybe an open source tool? (This is for my own curiousity as it sounds pretty cool)
OK, I see what you mean here with the structure. That makes sense to me and will update the issue description accordingly noting that it should (at minimum) have an opt-out. You won’t need to worry about this being done in the short term though, this particular issue is more of a backlog item for me.
Thanks!
They say you miss 100% of shots you don’t take so… if it is really beneficial to you and you (or the company you work for/with/that is using it etc) could financially contribute, that would be pretty awesome. I do offer support plans which can be helpful for businesses or even just a little something via GitHub Sponsors can go a long way.
If you can’t do that, spreading the word about MongoFramework (and/or any of my other projects) can also be helpful for the long term sustainability of my OSS projects.