RescueTime API와 spray-json을 통해 인터페이스를 시도하고 있습니다. 결과는 다음 형식과 같습니다.spray-json - 암시 적 확장이 다양 함
{
"notes":"data is an array of arrays (rows), column names for rows in row_headers",
"row_headers":[
"Rank",
"Time Spent (seconds)",
"Number of People",
"Activity",
"Category",
"Productivity"
],
"rows":[
[
1,
16611,
1,
"iTerm",
"Systems Operations",
2
]
]
}
아직까지는 오른쪽 사례 클래스를 해싱하려고 시도하고 있습니다. 여기에 지금까지있어 무엇 : 암시 적 확장을 발산에서 가장 거칠고의
Error:(31, 15) diverging implicit expansion for type spray.json.JsonWriter[test.RescueTimeApiResult]
starting with method rescueTimeApiResultFormat in object MyJsonProtocol
println(obj.toJson)
^
나의 이해 :
package test
import spray.json._
case class RescueTimeApiResult(notes: String, row_headers: List[String], rows: List[List[Either[Int, String]]])
object MyJsonProtocol extends DefaultJsonProtocol {
implicit def rescueTimeApiResultFormat[T: JsonFormat] = jsonFormat3(RescueTimeApiResult)
}
private object Tester extends App {
val notes = "data is an array of arrays (rows), column names for rows in row_headers"
val headers = List("Rank", "Time Spent (seconds)", "Number of People", "Activity", "Category", "Productivity")
val entry1 = List(wrapInt(1),
wrapInt(16611),
wrapInt(1),
wrapString("iTerm"),
wrapString("Systems Operations"),
wrapInt(2))
def wrapInt(x: Int): Either[Int, String] = Left(x)
def wrapString(s: String): Either[Int, String] = Right(s)
val rows = List(entry1)
val obj = RescueTimeApiResult(notes, headers, rows)
println(obj)
import MyJsonProtocol._
println(obj.toJson)
}
이 scalac
수율 잘 좋은,하지만 컴파일시. 대략 암시 적 검색에는주기가 있습니다. 알다시피, toJson
암시 적은 암시 적 JsonWriter
암시적인 spray.json._
가져 오기에서옵니다. 이것은 차례로 개체에 의해 제공됩니다. 그러나이 암시 적 매개 변수가 순환을 소개하는 이유는 저 밖에 있습니다. 한 이론은 Any
에 적용되는 toJson
변환이 암시 적 매개 변수 해석을 방해 할 수 있지만 이는 단지 직감에 불과합니다.
도움을 주시면 대단히 감사하겠습니다.