いくつかのクラスを json 文字列にエンコードしようとしていますが、何を試しても、クラスは使用しているケース クラスの暗黙的なエンコーダーを見つけることができないようです。
これは、私がそれを切り詰めることができた最小の例です。
import io.circe._
import io.circe.generic.semiauto._
import io.circe.generic.auto._
import io.circe.syntax._
case class OneCol(value: String)
object testObject {
def main(args: Array[String]): Unit = {
val testVal = OneCol("someVal")
println(testVal.asJson)
}
}
次のコンパイルエラーが発生します
エラー:(30, 21) パラメーター エンコーダーの暗黙的な値が見つかりませんでした: io.circe.Encoder[OneCol] println(testVal.asJson)
半自動エンコーダー作成で同じことを試しました
def main(args: Array[String]): Unit = {
implicit val enc : Encoder[OneCol] = deriveEncoder
val testVal = OneCol("someVal")
println(testVal.asJson)
}
次のエラーが発生します
エラー:(25, 42) タイプ io.circe.generic.encoding.DerivedObjectEncoder[A] 暗黙的 val enc の Lazy 暗黙的値が見つかりませんでした: Encoder[OneCol] = serveEncoder
エラー:(25, 42) メソッドの引数が不十分です。指定されていない値のパラメーター エンコード。暗黙の val enc : Encoder[OneCol] = serveEncoder
自動および半自動エンコーダー生成の全体的な目的は、このような状況を処理することであると確信しているため、何が間違っているのか少し途方に暮れています。
私はscala 2.10.4を使用しており、バージョン情報が関連する場合は0.7.0(circe-core_2.10、circe-generic_2.10アーティファクト)を使用しており、mavenをパッケージマネージャーとして使用しています。
これが失敗する理由と、適切にコンパイルする方法を知っている人はいますか?
編集:
マクロ プラグインを使用した私の POM のセクションを次に示します。リストされている両方のコンパイラ プラグイン (コメント付きとコメントなしの両方) を試しましたが、どちらも同じエラーが発生します。
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<configuration>
<args>
<!-- work-around for https://issues.scala-lang.org/browse/SI-8358 -->
<arg>-nobootcp</arg>
</args>
<recompileMode>incremental</recompileMode>
<compilerPlugins>
<compilerPlugin>
<groupId>org.scalamacros</groupId>
<artifactId>paradise_2.10.4</artifactId>
<version>2.1.0</version>
</compilerPlugin>
<!--<compilerPlugin>-->
<!--<groupId>org.scala-lang.plugins</groupId>-->
<!--<artifactId>macro-paradise_2.10.2</artifactId>-->
<!--<version>2.0.0-SNAPSHOT</version>-->
<!--</compilerPlugin>-->
</compilerPlugins>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile-first</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>