我有一个用 enumeratum 创建的枚举:
sealed trait Language extends EnumEntry
object Language
extends Enum[Language]
with PlayInsensitiveJsonEnum[Language] {
val values: IndexedSeq[Language] = findValues
case object DE extends Language
...
}
如果我在地图中使用它,它会抛出:
No instance of play.api.libs.json.Format is available for scala.collection.immutable.Map[finnova.bpf.api.entity.Language, java.lang.String] in the implicit scope (Hint: if declared in the same file, make sure it's declared before)
这是定义:
case class I18nEntry(values: Map[Language, String])
object I18nEntry {
implicit val jsonFormat: Format[I18nEntry] = Json.format[I18nEntry]
}
这在这里有效:
case class I18nEntry(values: Map[String, String], language: Language)