Comments (2)
Made a simple example repo showing this.
https://github.com/Doikor/jsonapi-scala-example
I will update the readme on this repo also.
from jsonapi-scala.
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)
from jsonapi-scala.
Related Issues (9)
- Cannot get it to work HOT 2
- Deserialization throws when optional relationship is set to null at incoming JSON. HOT 1
- The macros generate some dead code.
- Non-informative error message HOT 1
- How to get all of a resource? HOT 1
- JsonOption.withFilter() fails with MatchError
- No way to differentiate between empty list of ids and no ids at all for to-many relationships
- Add Scala 2.12 build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi-scala.