Lift Json throws error when trying to extract to a case class that has Map[String,Any]

14 views
Skip to first unread message

swetha kasireddy

unread,
Jul 6, 2018, 10:15:01 PM7/6/18
to Lift

Hi,

Lift Json is throwing error when trying to extract into a case class that has Map[String,Any]. Following is my case class, the Json that I have and the error. Any help on this is greatly appreciated.

case class TestClass(timestamp: String, test: Map[String,Any])


implicit val formats = DefaultFormats


val testVal = json.extract[TestClass]

{

"test": {
    "url": "test11",
    "pla": 2001,
    "project": "test_projectName"
  },
  "timestamp": "1530579464733"

}

net.liftweb.json.MappingException: No usable value for test

No information known about type

at net.liftweb.json.Meta$.fail(Meta.scala:227)

at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:438)

at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:385)

at net.liftweb.json.Extraction$$anonfun$15.apply(Extraction.scala:260)

at net.liftweb.json.Extraction$$anonfun$15.apply(Extraction.scala:260)

at scala.collection.immutable.List.map(List.scala:277)

at net.liftweb.json.Extraction$.instantiate$1(Extraction.scala:260)

at net.liftweb.json.Extraction$.newInstance$1(Extraction.scala:308)

at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:379)

at net.liftweb.json.Extraction$.extract0(Extraction.scala:444)

Matt Farmer

unread,
Jul 6, 2018, 10:22:05 PM7/6/18
to lif...@googlegroups.com
Hi there,

Lift-json doesn't support extracting to Map[String, Any] using the default extractors. Any doesn't have any innate type information, so lift-json balks when it encounters it in the default deserialization code. It will support extracting to Map[String, String]. If you must extract to Map[String, Any] you'll need to define a custom deserializer for the Any time and add that to your formats.

Here's the interface you'll need to define if you go that route: https://static.javadoc.io/net.liftweb/lift-json_2.12/3.3.0-RC1/net/liftweb/json/Serializer.html

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages