[JAVA-3962] Support missing bson field in documents Created: 26/Jan/21  Updated: 08/Feb/21  Resolved: 08/Feb/21

Status: Closed
Project: Java Driver
Component/s: Scala
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Gaël Ferrachat Assignee: Ross Lawley
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates JAVA-3551 Support default args in the CaseClass... Backlog
Documentation Changes Summary:

Something like:

If an bson array field is missing from the document, it will be populated as an empty collection at runtime.


 Description   

Goal: Be able to deserialize documents where

  • field is missing
  • field type is a child of `Iterable`

to ease changes in models without having to run scripts or write custom codecs.

 

Now, this won't work,
but we could expect that `metadata` and `aliases` are considered as empty, or at least having a setting in the client to enable it.

{
  "name": "John Doe"
}

 

 
case class Person(name: String, aliases: Set[String], metadata: Map[String, String])



 Comments   
Comment by Gaël Ferrachat [ 05/Feb/21 ]

Hi Ross,

Yes clearly. I can track 3551.

Thank you
Gael

Comment by Ross Lawley [ 05/Feb/21 ]

Hi gael.ferrachat@newsbridge.io,

I think being able to use default arguments would be the way to make this work see: JAVA-3551.

Would you agree?

Ross

Comment by Esha Bhargava [ 01/Feb/21 ]

gael.ferrachat@newsbridge.io Thank you for reporting this issue! We'll investigate this and get back to you.

Comment by Gaël Ferrachat [ 26/Jan/21 ]

Something close to how `Option`s are handled in fact.

Generated at Thu Feb 08 09:00:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.