Last active
January 6, 2016 15:18
-
-
Save fanf/496509318b32968fbc7e to your computer and use it in GitHub Desktop.
Implicit resolution error with Rapture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "demo" | |
version := "0.1" | |
scalaVersion := "2.11.7" | |
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" | |
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" | |
libraryDependencies ++= Seq( | |
"com.propensive" %% "rapture-core" % "2.0.0-M1" | |
, "com.propensive" %% "rapture-io" % "2.0.0-M1" | |
, "com.propensive" %% "rapture-uri" % "2.0.0-M1" | |
, "com.propensive" %% "rapture-net" % "2.0.0-M1" | |
, "com.propensive" %% "rapture-json" % "2.0.0-M1" | |
, "com.propensive" %% "rapture-json-jackson" % "2.0.0-M1" | |
, "com.propensive" %% "rapture-fs" % "2.0.0-M1" | |
// utilities | |
, "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0" | |
, "joda-time" % "joda-time" % "2.9.1" | |
, "org.joda" % "joda-convert" % "1.2" | |
// test | |
, "junit" % "junit" % "4.12" //to get the "RunWith" annotation | |
, "org.specs2" %% "specs2-core" % "3.6.5" % "test" | |
, "org.specs2" %% "specs2-junit" % "3.6.5" % "test" | |
) | |
scalacOptions += "-deprecation" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fanf | |
import rapture.core._ | |
import rapture.core.timeSystems.numeric | |
import rapture.io._ | |
import rapture.net._ | |
import rapture.json._ | |
import rapture.uri._ | |
import rapture.codec.encodings.`UTF-8`._ | |
import rapture.json.jsonBackends.jackson._ | |
object TestApi { | |
import TestData._ | |
val base = "https://some/api/" | |
trait User { | |
def help: String | |
def userGet(page: String) = { | |
val url = base + "/user" + page | |
implicit val httpTimeout = 500L | |
val res = Http.parse(url).httpGet() | |
val content = res.slurp[Char] | |
Json.parse(content) | |
} | |
} | |
object UserInfo extends User { | |
import MyExtractor._ | |
//adding that import, which import a "mode" requested afterward, | |
//does not change anything | |
//import modes.throwExceptions._ | |
val help = "Get general information about the user" | |
// This method does not compile with the following messages: | |
//- cannot extract type Vector[fanf.TestData.Item] from rapture.json.Json | |
// (this is coming from https://github.com/propensive/rapture-data/blob/master/src/extractors.scala#L109 ) | |
//- not enough arguments for method as: (implicit ext: rapture.data.Extractor[Vector[fanf.TestData.Item],rapture.json.Json], implicit | |
// mode: rapture.core.Mode[rapture.data.Data#as])mode.Wrap[Vector[fanf.TestData.Item],ext.Throws]. Unspecified value parameters ext, mode. | |
def shouldWork = userGet("/items").as[Vector[Item]] | |
// passing argument explicitly works | |
def explicitArgumentsOK = userGet("/items").as[Vector[Json]].map( | |
_.as[Item](itemExtractor, modes.throwExceptions.apply()) | |
) | |
} | |
} | |
object TestData { | |
final case class Item( | |
uuid: String | |
, amount: Double | |
//this is the faulty part, with for ex String in place of | |
//Status, "shouldWork" method compiles | |
, status: Status | |
) | |
sealed trait Status | |
case object Delivered extends Status | |
} | |
object MyExtractor { | |
import TestData._ | |
implicit val itemExtractor = Json.extractor[Json].map { json => | |
Item( | |
json.uuid.as[String] | |
, json.amount.as[Double] | |
, Delivered | |
) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As requested by Jon Pretty, I opened an issue on that subject: propensive/rapture#40