【问题标题】:Scala 3 + http4s problem with encode/decode jsonScala 3 + http4s 的编码/解码 json 问题
【发布时间】:2021-12-25 20:59:22
【问题描述】:

我有一个 Scala 3 项目(3.0.0 版本),我正在尝试使用 http4s 构建简单的 Rest API。

我在解码/编码 JSON 时遇到问题。

我正在基于http4s.g8 构建我的代码。

问题出现在this line:

implicit val jokeDecoder: Decoder[Joke] = deriveDecoder[Joke]

编译错误:

在对象 semiauto 中找不到方法 deriveDecoder 的参数 A 类型的隐式参数 semiauto

Scala 3 是否有一些变化使其与众不同?

我的依赖

scalaVersion := "3.0.0"

val Http4sVersion = "0.23.6"
val CirceVersion = "0.14.1"

libraryDependencies ++= Seq(
  "org.http4s"      %% "http4s-blaze-server" % Http4sVersion,
  "org.http4s"      %% "http4s-blaze-client" % Http4sVersion,
  "org.http4s"      %% "http4s-circe"        % Http4sVersion,
  "org.http4s"      %% "http4s-dsl"          % Http4sVersion,

  "io.circe"        %% "circe-core"          % CirceVersion,
  "io.circe"        %% "circe-generic"       % CirceVersion
)

【问题讨论】:

    标签: scala scala-3 http4s


    【解决方案1】:
    final case class Joke(joke: String) extends AnyVal 
    

    是杯子。改写为

    final case class Joke(joke: String) 
    

    它应该可以工作

    【讨论】:

      猜你喜欢
      • 2019-09-10
      • 1970-01-01
      • 2017-06-12
      • 2023-04-09
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多