Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB:一般使用createCodecProvider_Mongodb_Scala_Generics_Typeclass_Codec - Fatal编程技术网

MongoDB:一般使用createCodecProvider

MongoDB:一般使用createCodecProvider,mongodb,scala,generics,typeclass,codec,Mongodb,Scala,Generics,Typeclass,Codec,而不是每个案例类有一个硬编码行 val codecRegistry = fromRegistries( fromProviders( classOf[CaseClassNameGoesHere], ... ), ... ) 我想创建一个可以创建它们的方法 两者 及 。。。给我scala.ScalarReflectionException:类型T不是类 我希望编译器能够查看此方法的每次调用并执行它的操作 有没有办法做到这一点?只要我不必

而不是每个案例类有一个硬编码行

  val codecRegistry = fromRegistries(
    fromProviders(
      classOf[CaseClassNameGoesHere],
      ...
    ),
    ...
    )
我想创建一个可以创建它们的方法

两者

。。。给我scala.ScalarReflectionException:类型T不是类

我希望编译器能够查看此方法的每次调用并执行它的操作


有没有办法做到这一点?只要我不必创建
classOf
s的列表,“远离”这种方法的解决方案仍然会被接受。

你只会得到更多的代码和更复杂的代码,不是吗?当您将[Foo]类传递给
fromProviders
时,实际上只有一个隐式的
CreateCodeProvider
,它接受一个
类[Foo]
并为其创建一个
CodeProvider
。您仍然必须“手动”将所有编解码器提供程序从提供程序传递到
中,而不管您如何生成它们。i、 e.你最终还是会得到这样的结果:

val codecRegistry = fromRegistries(
  fromProviders(
    method[Foo],
    method[Bar],
    ...
  )

你会得到更多的代码,更复杂的代码,不是吗?当您将[Foo]
类传递给
fromProviders
时,实际上只有一个隐式的
CreateCodeProvider
,它接受一个
类[Foo]
并为其创建一个
CodeProvider
。您仍然必须“手动”将所有编解码器提供程序从提供程序传递到
中,而不管您如何生成它们。i、 e.你最终还是会得到这样的结果:

val codecRegistry = fromRegistries(
  fromProviders(
    method[Foo],
    method[Bar],
    ...
  )
val codecRegistry = fromRegistries(
  fromProviders(
    method[Foo],
    method[Bar],
    ...
  )