-
Notifications
You must be signed in to change notification settings - Fork 24
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
Example in readme failing #63
Comments
argonaut-shapeless only works with argonaut 6.1 for now. I'm running into problems with the covariance of |
I have observed same issue. In attempt to trace the problem I created a new project with just this library as a dependency. My name := "Argonaut Shapeless Test"
version := "0.1"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"com.github.alexarchambault" %% "argonaut-shapeless_6.1" % "1.1.0-RC2"
) The test class: import argonaut._, Argonaut._, Shapeless._
object Test {
sealed trait Base
case class First(i: Int) extends Base
case class Second(s: String) extends Base
// encoding
val encode = EncodeJson.of[Base]
val json = encode(First(2))
json.nospaces == """{"First":{"i":2}}"""
// decoding
val decode = DecodeJson.of[Base]
val result = decode.decodeJson(json)
result == DecodeResult.ok(First(2))
}
Errors on compiling:
However it seems odd that pasting the following into the console works: import argonaut._, Argonaut._, Shapeless._
sealed trait Base
case class First(i: Int) extends Base
case class Second(s: String) extends Base
// encoding
val encode = EncodeJson.of[Base]
val json = encode(First(2))
json.nospaces == """{"First":{"i":2}}"""
// decoding
val decode = DecodeJson.of[Base]
val result = decode.decodeJson(json)
result == DecodeResult.ok(First(2)) Changing where the model classes are declared to outside of the test class works:
But this doesn't:
This is all because of the way macros work and compile order (Shapless uses macros to fill in the implicits here). It works in the REPL because everything is ordered and compiled on the fly, however when using I would recommend that the best way around this is to have the model classes in a separate module to the JSON parsing, that way the model classes will always be built first and the code will compile. Would it be worth an update to the readme to describe this behaviour (I'm happy to raise a PR)? |
@janstenpickle If you want to add a word about this issue (this is the classic SI-7046, aka SI-7755), go for it! Putting the models and the codec derivations in different projects is indeed the most reliable way of addressing that afaik. |
If you change the README, change the one under |
Errors:
The text was updated successfully, but these errors were encountered: