I am trying to make a generic function which produces a CodecProvider
from a given generic case class.
The BSON macro documentation does not give any examples of this.
This (unanswered) SO question is similar, however I am not interested in enumerating all possible codec's for a given type parameter. Also, my question does not deal with type bounds or type variances.
Here is a minimal example of the code which does not compile.
import org.mongodb.scala.bson.codecs.Macros
case class Foo(x: Int)
case class Bar[T](x: T)
def fooCodecProvider = Macros.createCodecProvider[Foo]()
// Compiles! (No generic)
def barCodecProvider[T] = Macros.createCodecProvider[Bar[T]]()
// Compile Error:(8, 70) class Bar takes type parameters
I expect the barCodecProvider
to compile, however it does not.
The compilation error thrown by the above code reads class Bar takes type parameters
which is confusing because I have clearly provided the type parameter T
to Bar
via the signature of the generic barCodecProvider
function. Do I have a typing-related syntax error? Is error a sign that I am using the mongo-scala-driver incorrectly?