【发布时间】:2016-03-09 05:28:09
【问题描述】:
我有类型的对象
Map[java.util.Locale, String]
我怎样才能为此进行 Json 写入/读取?我看过coupleotherquestions,但自己想不出解决方案。我得到了(但尚未测试)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]] = ???
?
【问题讨论】:
标签: json scala playframework play-json