MappingException when using the Lift JSON Parser giving cryptic error message

2,341 views
Skip to first unread message

lifter

unread,
Mar 29, 2011, 8:23:01 PM3/29/11
to Lift
Im getting a strange exception with the JSON extractor,
"net.liftweb.json.MappingException: No usable value for $outer"... has
anyone seen this before / can point me in the right direction to fix
this?

Here's some context: I'm writing a program that uses an API. The API
spits out JSON in the form of:
{"status":"ok","error":"","invited_users":[],"folder_id":
63785069,"folder_name":"rrrrrrrrrrrrr"}

Basically Im trying to determine whether or not I got a successful
message. If it doesnt conform to that pattern, something bad happened
and I dont really care.

def isGood(response: String): Boolean =
{
try
{
case class FolderCreateSuccessResponse(status: String, error:
String, invited_users: List[Long], folder_id: Long, folder_name:
String)
implicit val formats = DefaultFormats //need this line or wont
compile, idk why
val resp : FolderCreateSuccessResponse =
parse(response).extract[FolderCreateSuccessResponse]
return resp.status == "ok"
}
catch {
case me : MappingException => {
// do nothing... i dont care
}
}
return false
}

For this given input, I get the following stack trace
Input String: {"status":"ok","error":"","invited_users":[],"folder_id":
6926246,"folder_name":"new folder"}


Trace:
net.liftweb.json.MappingException: No usable value for $outer
No usable value for myInfo
No usable value for pkg
Did not find value which can be converted into java.lang.String
at net.liftweb.json.Meta$.fail(Meta.scala:128)
at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:275)
at net.liftweb.json.Extraction$.build$1(Extraction.scala:242)
at net.liftweb.json.Extraction$$anonfun$4.apply(Extraction.scala:194)
at net.liftweb.json.Extraction$$anonfun$4.apply(Extraction.scala:194)
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.Extraction$.instantiate$1(Extraction.scala:194)
at net.liftweb.json.Extraction$.newInstance$1(Extraction.scala:222)
at net.liftweb.json.Extraction$.build$1(Extraction.scala:240)
at net.liftweb.json.Extraction$.extract(Extraction.scala:284)
at net.liftweb.json.Extraction$.extract0(Extraction.scala:172)
at net.liftweb.json.Extraction$.extract(Extraction.scala:40)
at net.liftweb.json.JsonAST$JValue.extract(JsonAST.scala:288)

a weird thing is the myInfo and pkg variables are listed there...
myInfo is an object and has a property named pkg, but they should be
unrelated

David Pollak

unread,
Mar 29, 2011, 9:09:24 PM3/29/11
to lif...@googlegroups.com
The case class has to be defined at the outer level of your class hierarchy.

The error is that there's a hidden field for all inner classes called $outer.  The Lift-JSON reflection code cannot find a way to resolve this field.


--
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
Reply all
Reply to author
Forward
0 new messages