[JAVA-3814] Support BsonIgnore annotation for Scala case classes Created: 13/Aug/20  Updated: 28/Oct/23  Resolved: 12/Jan/21

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

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


 Description   

Goal: Add a way to ignore BSON serialization of a case class field.

Context**: We don't want to store into MongoDB some case class fields (eg. computed from other sources or used for binary serialization). But we don't want (sometimes we can't) wrap them into Option (eg. to avoid things like Option[Seq[T]]).

 

I saw Java Driver has a BsonIgnore annotation, could it be possible to implement it ? It can cause issues for types that have no default constructor or default value but it could be prerequisite ?

For example

case class Picture(
                    height: Int,
                    width: Int,
                    @BsonIgnore
                    metadata: Seq[Metadata] = Seq.empty
                  )



 Comments   
Comment by Githook User [ 12/Jan/21 ]

Author:

{'name': 'Gaël Ferrachat', 'email': 'gael-ft@users.noreply.github.com', 'username': 'gael-ft'}

Message: Added Scala BsonIgnore annotation (#584)

JAVA-3814
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/f81cc87c0cc75b72f2b317b74e93dd1de738711d

Comment by Gaël Ferrachat [ 13/Aug/20 ]

Note we would like to avoid creating our own codecs and keep using Macros

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