Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error "Cannot find JsonApiReader or JsonApiFormat type class" #21

Closed
zhanglongyang opened this issue Nov 13, 2017 · 2 comments
Closed

Comments

@zhanglongyang
Copy link

Just found that with Scala version 2.12.3, I'm stilling having the issue (#11).
Is there anything wrong with my code? or does it fully support scala 2.12 yet? :)
Thanks.

build.sbt

scalaVersion := "2.12.3"
libraryDependencies ++= Seq(
  "com.qvantel" %% "jsonapi-scala-core" % "5.1.2",
  "io.spray" %%  "spray-json" % "1.3.3"
)
Welcome to Scala 2.12.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import _root_.spray.json.DefaultJsonProtocol._
import com.qvantel.jsonapi._

implicit val apiRoot: ApiRoot = ApiRoot(None)

@jsonApiResource final case class Employee(id: String, name: String)
@jsonApiResource final case class Company(id: String, name: String, employees: ToMany[Employee])

val acme = Company("1", "acme", ToMany.loaded(Seq(Employee("1", "number one 1"))))

val json = rawOne(acme)
val parsed = readOne[Company](json, Set("employees"))

acme == parsed // true

// Exiting paste mode, now interpreting.

<console>:19: error: could not find implicit value for evidence parameter of type com.qvantel.jsonapi.Identifiable[Employee]
       val acme = Company("1", "acme", ToMany.loaded(Seq(Employee("1", "number one 1"))))
                                                    ^
<console>:22: error: Cannot find JsonApiReader or JsonApiFormat type class for Company
       val parsed = readOne[Company](json, Set("employees"))
@Doikor
Copy link
Collaborator

Doikor commented Nov 14, 2017

You need to add macro paradise plugin for it to work. Another thing I've forgotten to mention in the readme I guess :(

When using the console from the project (so the macro paradise is added) it works

sbt:jsonapi-scala> ++2.12.3
[info] Setting Scala version to 2.12.3 on 3 projects.
[info] Excluded 2 projects, run ++ 2.12.3 -v for more details.
[info] Reapplying settings...
[info] Set current project to jsonapi-scala (in build file:/Users/ahuttunen/code/jsonapi-scala/)
sbt:jsonapi-scala> core/console

... bunch of stuff compiling

Welcome to Scala 2.12.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import _root_.spray.json.DefaultJsonProtocol._
import com.qvantel.jsonapi._

implicit val apiRoot: ApiRoot = ApiRoot(None)

@jsonApiResource final case class Employee(id: String, name: String)
@jsonApiResource final case class Company(id: String, name: String, employees: ToMany[Employee])

val acme = Company("1", "acme", ToMany.loaded(Seq(Employee("1", "number one 1"))))

val json = rawOne(acme)
val parsed = readOne[Company](json, Set("employees"))

acme == parsed // true

// Exiting paste mode, now interpreting.

import _root_.spray.json.DefaultJsonProtocol._
import com.qvantel.jsonapi._
apiRoot: com.qvantel.jsonapi.ApiRoot = ApiRoot(None)
defined class Employee
defined object Employee
defined class Company
defined object Company
acme: Company = Company(1,acme,Loaded(List(Employee(1,number one 1))))
json: spray.json.JsObject = {"data":{"attributes":{"name":"acme"},"relationships":{"employees":{"data":[{"type":"employees","id":"1"}],"links":{"related":"/companies/1/employees"}}},"links":{"self":"/companies/1"},"id":"1","type":"companies"},"included":[{"type":"employees","attributes":{"name":"number one 1"},"id":"1","links":{"self":"/employees/1"}}]}
parsed: Company = Company(1,acme,Loaded(List(...

So try adding this to your build.sbt

resolvers += Resolver.sonatypeRepo("releases")
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)

@Doikor
Copy link
Collaborator

Doikor commented Nov 14, 2017

Made a simple example repo showing this.

https://github.com/Doikor/jsonapi-scala-example

I will update the readme on this repo also.

Doikor pushed a commit to Doikor/jsonapi-scala that referenced this issue Nov 14, 2017
@Doikor Doikor closed this as completed Nov 14, 2017
Doikor pushed a commit to Doikor/jsonapi-scala that referenced this issue Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants