Unable to deserialize JSON for a case class that uses a trait #1493

dkharrat opened this Issue Sep 13, 2013 · 1 comment


None yet

2 participants


If I have the following case class:

case class Foo[T](a: T, b: String)

trait FooFormatter {
   override def toString() = "foo"

type FooWithFormatter = Foo[Int] with FooFormatter

val a = JsonParser.parse("""[{"a": 2, "b": "text"}]""").extract[List[FooWithFormatter]]

I get the following exception:

Caused by: net.liftweb.json.MappingException: No constructor for type class java.lang.Object, JInt(2)
    at net.liftweb.json.Meta$.fail(Meta.scala:191) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at net.liftweb.json.Extraction$$anonfun$findBestConstructor$1$1.apply(Extraction.scala:216) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at net.liftweb.json.Extraction$$anonfun$findBestConstructor$1$1.apply(Extraction.scala:216) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at scala.Option.getOrElse(Option.scala:120) [scala-library.jar:na]
    at net.liftweb.json.Extraction$.findBestConstructor$1(Extraction.scala:216) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at net.liftweb.json.Extraction$.instantiate$1(Extraction.scala:251) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at net.liftweb.json.Extraction$.newInstance$1(Extraction.scala:286) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:315) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:351) ~[lift-json_2.10-2.5.1.jar:2.5.1]
    ... 51 common frames omitted

If I define the type FooWithFormatter without the trait as:

type FooWithFormatter = Foo[Int]

Things work fine. Any reason why this is happening? Is there a particular way to get it to work?

Lift Web Framework member

This is not the correct forum to ask questions. Please ask them on the Lift google group. http://liftweb.net/community

@dpp dpp closed this Sep 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment