Skip to content

Simple play-json example #65

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

Open
TylerPachal opened this issue Aug 3, 2016 · 4 comments
Open

Simple play-json example #65

TylerPachal opened this issue Aug 3, 2016 · 4 comments

Comments

@TylerPachal
Copy link

TylerPachal commented Aug 3, 2016

I am trying to make a simple example using play-json, but am running into a run-time error.

build.sbt

name := "JsonApiTest"
version := "1.0"
scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
    "org.zalando" %% "scala-jsonapi" % "0.5.2",
    "com.typesafe.play" %% "play-json" % "2.5.4",
    "io.spray" %% "spray-httpx" % "1.3.3"
)

main.scala

import org.zalando.jsonapi.{JsonapiRootObjectWriter, _}
import org.zalando.jsonapi.json.playjson.PlayJsonJsonapiSupport._
import org.zalando.jsonapi.model.JsonApiObject.StringValue
import org.zalando.jsonapi.model.RootObject.ResourceObject
import org.zalando.jsonapi.model.{Attribute, RootObject}
import play.api.libs.json._

case class Person(id: String, name: String)
object Person {
    implicit val personJsonapiRootObjectWriter: JsonapiRootObjectWriter[Person] = new JsonapiRootObjectWriter[Person] {
        override def toJsonapi(person: Person) = {
            RootObject(data = Some(ResourceObject(
                `type` = "person",
                id = Some(person.id.toString),
                attributes = Some(List(
                    Attribute("name", StringValue(person.name))
                )), links = None)
            ))
        }
    }
}

object main {
    def main(args: Array[String]) {
        val p = Person("asd3nbs32g5", "Tyler")
        val j = Json.toJson(p.rootObject)
    }
}

Error:

java.lang.NoSuchMethodError: play.api.libs.functional.syntax.package$.functionalCanBuildApplicative(Lplay/api/libs/functional/Applicative;)Lplay/api/libs/functional/FunctionalCanBuild;
    at org.zalando.jsonapi.json.playjson.PlayJsonJsonapiFormat$class.rootObjectFormat(PlayJsonJsonapiFormat.scala:18)
    at org.zalando.jsonapi.json.playjson.PlayJsonJsonapiSupport$.rootObjectFormat$lzycompute(PlayJsonJsonapiSupport.scala:19)
    at org.zalando.jsonapi.json.playjson.PlayJsonJsonapiSupport$.rootObjectFormat(PlayJsonJsonapiSupport.scala:19)
    at main$.main(main.scala:26)
    at main.main(main.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

It will work if I use spray instead of play.

@zmeda
Copy link
Contributor

zmeda commented Aug 4, 2016

With the current project structure it is very inconvenient to upgrade to play 2.5. I'm in the middle of refactoring the whole project and which would make our life easier. :-)
Please have a look on issue #64. I pushed some changes to a branch already but it does not compile yet. Working hard on that as much as my free time allows me.
Stay tuned.

@zmeda zmeda added the duplicate label Aug 4, 2016
@tianhao-au
Copy link

@zmeda could I follow up how is the progress of upgrading to play 2.5? Any time about the release? Thanks.

@zmeda
Copy link
Contributor

zmeda commented Feb 21, 2017

@ysihaoy a lot of work has already been done. https://github.com/zalando/scala-jsonapi/tree/issue/64 but help is much appreciated

@pettercastro
Copy link

pettercastro commented Sep 11, 2019

@zmeda did you have time to check it out? as I am getting the same error when using play framework 2.7.3 and this library version 0.6.2 and "io.spray" %% "spray-httpx" % "1.3.3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants