[JAVA-3551] Support default args in the CaseClassCodec Created: 08/Jun/17  Updated: 26/Oct/22

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

Type: New Feature Priority: Major - P3
Reporter: Ross Lawley Assignee: Unassigned
Resolution: Unresolved Votes: 7
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-3962 Support missing bson field in documents Closed
Related
is related to JAVA-3544 Macro for case class with default val... Backlog

 Description   

Add support for default args. See PR: https://github.com/mongodb/mongo-scala-driver/pull/30



 Comments   
Comment by Gaël Ferrachat [ 27/Jul/21 ]

Hi Ross,

Would it be acceptable to have some default handling based on types themselves and not default values ?

Having Json4s in mind and the concept of "withStrictArrayExtraction", or what is already done for Option
It would probably solve many of situation where the expected default value is an empty seq, empty map, None ...
In those scenarios we don't need default methods in the companion anymore, simply providing Seq.empty, Map.empty, None
More complexe logic would probably have to keep writing codecs of course

It could be an argument of the createCodecProvider for example or an annotation ...

Gaël

Comment by Ross Lawley [ 27/Jul/21 ]

Hi gael.ferrachat@newsbridge.io,

There are no current plans to look into adding support. Unfortunately, the previous attempt ran into a compile time race condition and had to be reverted (SCALA-324).

Ross

Comment by Gaël Ferrachat [ 22/Jul/21 ]

Hi Ross,

Do we have any target time on this ?

Last commit was done in 2017 and it would greatly improves some of our coding strategies ...

Comment by Githook User [ 22/Aug/17 ]

Author:

{'username': 'rozza', 'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley'}

Message: Reverted SCALA-313 support for default arguments

Requires a better strategy for handling compiler race conditions where
the companion objects default methods may not exist.
Branch: master
https://github.com/mongodb/mongo-scala-driver/commit/233afcc52c81f35b0aeec04ee44a66cda9010abd

Comment by Ross Lawley [ 22/Aug/17 ]

As SCALA-325 and SCALA-324 show there have been a number of issues with supporting default values.

For 2.2.0 the changes will be reverted and will remain so until we can add a compile time error explaining the reason the macro cannot work.

Comment by Githook User [ 14/Jul/17 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Docs: Added note regarding default values and companion Objects

SCALA-313 SCALA-324
Branch: master
https://github.com/mongodb/mongo-scala-driver/commit/e89f3b7fcf6cbb12b0a623d47afc2721ac464f87

Comment by Githook User [ 08/Jun/17 ]

Author:

{u'username': u'Panshin', u'name': u'Gleb Panshin', u'email': u'panshingleb@gmail.com'}

Message: CaseClassCodec - Added support for case classes containing val attributes

SCALA-313
Branch: master
https://github.com/mongodb/mongo-scala-driver/commit/5e620c8ff3216a69cc5366659512dbf7e89d0124

Comment by Githook User [ 08/Jun/17 ]

Author:

{u'username': u'Panshin', u'name': u'Gleb Panshin', u'email': u'panshingleb@gmail.com'}

Message: CaseClassCodec - Added support for default values.

SCALA-313
Branch: master
https://github.com/mongodb/mongo-scala-driver/commit/e27ecd9817c6f88a4f5ca34b2115706e511db49c

Generated at Thu Feb 08 08:59:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.