我有类型的对象
Map[java.util.Locale, String]
我怎样才能为此进行 Json 写入/读取?我查看了其他几个 问题,但自己无法提出解决方案。我得到了(但还没有测试过)Locale 的东西
implicit val localeReads: Reads[Locale] = new Reads[Locale] {
def reads(json: JsValue): JsResult[Locale] =
json match {
case JsString(langString) => JsSuccess(new Locale(langString))
case _ => JsError("Locale Language String Expected")
}
}
implicit val localeWrites: Writes[Locale] = new Writes[Locale] {
def writes(locale: Locale) = JsString(locale.toString)
}
然后我该如何使用它
implicit val myMapReads: Reads[Map[Locale, String]] = ???
implicit val myMapWrites: Writes[Map[Locale, String]] = ???
?