JSON: can't extract case class with Map[String, List[String]] member

313 views
Skip to first unread message

Guy Bolton King

unread,
Sep 21, 2010, 9:52:27 AM9/21/10
to lif...@googlegroups.com
Hi,

This is my first post, so before I start trying to report bugs: thanks for a great framework!

Anyway, the last line in the following code throws a ClassCastException using Lift-2.1-RC1 on scala-2.8.0-final

import net.liftweb.json
import json.DefaultFormats
import json.Extraction.decompose

implicit val formats = DefaultFormats

case class Map1(m: Map[String, String])
val map1 = Map1(Map("a" -> "b", "c" -> "d"))
val json1 = decompose(map1)
assert(json1.extract[Map1] == map1)

case class Map2(m: Map[String, List[String]])
val map2 = Map2(Map("a" -> List("b"), "c" -> List("d")))
val json2 = decompose(map2)
assert(json2.extract[Map2] == map2)

(The Maps are contained in case classes because of the "Root object can't yet be List or Map (needs a feature from Scala 2.8)" issue).

Writing a custom Serializer for Map2 doesn't work, as the exception appears to be thrown before any custom deserialization is even looked up.

The stack trace reads as follows:

Exception in thread "main" net.liftweb.json.MappingException: unknown error
at net.liftweb.json.Extraction$.extract(Extraction.scala:43)
at net.liftweb.json.JsonAST$JValue.extract(JsonAST.scala:288)
at net.enhancededitions.paymenttracker.scratch.Scratch$.main(Scratch.scala:23)
at net.enhancededitions.paymenttracker.scratch.Scratch.main(Scratch.scala)
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at net.liftweb.json.Meta$Reflection$.types$1(Meta.scala:228)
at net.liftweb.json.Meta$Reflection$.typeConstructors(Meta.scala:235)
at net.liftweb.json.Meta$.mkContainer$1(Meta.scala:89)
at net.liftweb.json.Meta$.fieldMapping$1(Meta.scala:109)
at net.liftweb.json.Meta$.toArg$1(Meta.scala:117)
at net.liftweb.json.Meta$$anonfun$constructors$1$1$$anonfun$apply$1.apply(Meta.scala:83)
at net.liftweb.json.Meta$$anonfun$constructors$1$1$$anonfun$apply$1.apply(Meta.scala:82)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:206)
at scala.collection.immutable.List.map(List.scala:45)
at net.liftweb.json.Meta$$anonfun$constructors$1$1.apply(Meta.scala:82)
at net.liftweb.json.Meta$$anonfun$constructors$1$1.apply(Meta.scala:81)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:206)
at scala.collection.immutable.List.map(List.scala:45)
at net.liftweb.json.Meta$.constructors$1(Meta.scala:81)
at net.liftweb.json.Meta$$anonfun$mappingOf$1.apply(Meta.scala:122)
at net.liftweb.json.Meta$$anonfun$mappingOf$1.apply(Meta.scala:122)
at net.liftweb.json.Meta$Memo.memoize(Meta.scala:141)
at net.liftweb.json.Meta$.mappingOf(Meta.scala:122)
at net.liftweb.json.Extraction$.extract(Extraction.scala:176)
at net.liftweb.json.Extraction$.extract0(Extraction.scala:172)
at net.liftweb.json.Extraction$.extract(Extraction.scala:40)
... 3 more

Sorry not to propose a solution: the code in Extraction.scala is a little beyond me, I'm afraid. I don't seem to have permission to raise tickets in Assembla, else I would have raised this there.

Many thanks,

Guy.

Joni Freeman

unread,
Sep 21, 2010, 1:23:37 PM9/21/10
to Lift
Hi,

A fix is in reviewboard now: http://reviewboard.liftweb.net/r/452/

Cheers Joni

Guy

unread,
Sep 21, 2010, 3:29:28 PM9/21/10
to Lift


On Sep 21, 6:23 pm, Joni Freeman <freeman.j...@gmail.com> wrote:
> Hi,
>
> A fix is in reviewboard now:http://reviewboard.liftweb.net/r/452/

Fantastic! I've tested it locally, and it works for me as well. Is
there any chance of getting this into 2.1 (he asks hopefully)?

Cheers,

Guy.

David Pollak

unread,
Sep 21, 2010, 5:53:08 PM9/21/10
to lif...@googlegroups.com

Sorry no.  Barring some catastrophic bug 2.1 is what is in rc3

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>

Guy

unread,
Sep 21, 2010, 6:42:30 PM9/21/10
to Lift


On Sep 21, 10:53 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Sorry no.  Barring some catastrophic bug 2.1 is what is in rc3

Oh well, never mind. It's great that you've got 2.1 with the sbt +
Scala 2.8 support out so soon after 2.0: thank you.

Back to snapshots for me: am I right in thinking that the nightly
builds are made on the 2.x-2.8_devel branch in git?

Cheers,

Guy.

David Pollak

unread,
Sep 21, 2010, 6:44:48 PM9/21/10
to lif...@googlegroups.com
On Tue, Sep 21, 2010 at 3:42 PM, Guy <g...@waftex.com> wrote:


On Sep 21, 10:53 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Sorry no.  Barring some catastrophic bug 2.1 is what is in rc3

Oh well, never mind.  It's great that you've got 2.1 with the sbt +
Scala 2.8 support out so soon after 2.0: thank you.

Yeah... and 2.2 will be out in early January.
 

Back to snapshots for me: am I right in thinking that the nightly
builds are made on the 2.x-2.8_devel branch in git?

Yep and we'll have a stable 2.2-M1 in early November.
 

Cheers,

Guy.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics
Reply all
Reply to author
Forward
0 new messages