How to use Jerksson with listings?

I am trying to use Jerkson to create a Json representation of Enumeration in a method that uses a generic type but looks weird. I also tried using random objects, but the Json result dispenser also looks good:

object WeekDay extends Enumeration {
  type WeekDay = Value
  val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}

trait Letter
case object A extends Letter
case object B extends Letter
case object C extends Letter

object Test extends App {
  import com.codahale.jerkson.Json._

  import WeekDay._
  def printWeekDay(weekday: WeekDay) {println("weekday: " + generate(weekday))}
  printWeekDay(Mon)

  def printLetter(letter: Letter) {println("letter: " + generate(letter))}
  printLetter(A)
}

When doing this, I get:

weekday: {"$outer":{"ValueSet$module":null},"scala$Enumeration$Val$$i":0}
letter: {}

Any ideas on how to get the correct value in Json?

+3
source share
1 answer

you may need an implicit conversion between your Enumeration and jerkson.Json.JsValue.

playframework uses this approach

http://www.playframework.org/documentation/api/2.0/scala/index.html#play.api.libs.json.Writes

0
source

All Articles