Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Unable to find a case accessor exception in test driver #61

Open
janihur opened this issue Jun 2, 2012 · 0 comments
Open

Unable to find a case accessor exception in test driver #61

janihur opened this issue Jun 2, 2012 · 0 comments

Comments

@janihur
Copy link

janihur commented Jun 2, 2012

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)
  }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant