jerkson
jerkson copied to clipboard
Unable to find a case accessor exception in test driver
This might be related to issue #52, but I'm not sure thought.
I'm using sbt (sbt run) where the following code snippet works as expected (JSON from/to case class conversion works fine):
package net.janihur.jerksonex
import com.codahale.jerkson.Json.{generate,parse}
object Main {
case class Request(request: String = "GET_ITEMS",
requestId: Int = 123,
categories: List[Int] = List())
def main(args: Array[String]) {
println("jerksonex starts")
val req = Request()
val json = generate(req)
println("1: " + json)
val req2 = parse[Request](json)
println("2: " + req2.toString)
println("jerksonex ends")
}
}
But when I put the same code to a test driver (sbt test) I'll get an exception:
[info] com.codahale.jerkson.ParsingException: Unable to find a case accessor for net.janihur.jerksonex.test.MainTest$Request
[info] at com.codahale.jerkson.ParsingException$.apply(ParsingException.scala:17)
[info] at com.codahale.jerkson.Parser$class.parse(Parser.scala:86)
[info] at com.codahale.jerkson.Json$.parse(Json.scala:6)
[info] at com.codahale.jerkson.Parser$class.parse(Parser.scala:14)
[info] at com.codahale.jerkson.Json$.parse(Json.scala:6)
I'm using ScalaTest:
package net.janihur.jerksonex.test
import org.scalatest.FunSuite
import com.codahale.jerkson.Json.{generate,parse}
class MainTest extends FunSuite {
case class Request(request: String = "GET_ITEMS",
requestId: Int = 123,
categories: List[Int] = List())
test("foo") {
val req = Request()
val json = generate(req)
info("1: " + json)
val req2 = parse[Request](json)
info("2: " + req2.toString)
}
}