Skip to content

Commit

Permalink
add support for IndexedSeq in MacroBsonFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
SakulK committed Feb 6, 2024
1 parent 7e8eec2 commit 42f1437
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ object MacroBsonFormat extends MacroBsonFormatDeriving:
): MacroBsonFormat[Seq[T]] =
IterableLikeMacroFormat[T, Seq[T]](tf)

implicit def indexedSeqMacroFormat[T](using
tf: MacroBsonFormat[T]
): MacroBsonFormat[IndexedSeq[T]] =
IterableLikeMacroFormat[T, IndexedSeq[T]](tf)

implicit def listMacroFormat[T](using
tf: MacroBsonFormat[T]
): MacroBsonFormat[List[T]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ object OX:
case class InnerC(i: Int, v: Option[String])
case class OuterC(i: InnerC, o: Seq[InnerC])

case class DerivesC(i: Int, v: Option[String]) derives MacroBsonFormat
case class DerivesC(i: Int, v: Option[String], b: IndexedSeq[String])
derives MacroBsonFormat

class MacroDerivationTests extends FunSuite:
val oid = ObjectId()
Expand Down Expand Up @@ -65,7 +66,7 @@ class MacroDerivationTests extends FunSuite:
}

test("case class with derives") {
roundTrip[DerivesC](DerivesC(2, Some("b")))
roundTrip[DerivesC](DerivesC(2, Some("b"), IndexedSeq("c")))
}

inline def roundTrip[T](v: T)(using t: MacroBsonFormat[T]) =
Expand Down

0 comments on commit 42f1437

Please sign in to comment.