scala convert String to generic type -


i am parsing json. convert it's values other types . i.e

//json = json string  val seq = net.liftweb.json.parse(json).\\("seq").values.tostring.tolong val username = net.liftweb.json.parse(json).\\("name").values.tostring val intnum = net.liftweb.json.parse(json).\\("intid").values.toint 

i cast using generic method more "scala" way, tried this:

object converter{   def jsoncaster[t](json:string,s:string):t={     net.liftweb.json.parse(json).\\(s).values.tostring.asinstanceof[t]   } } 

but got casting error :

java.lang.classcastexception: java.lang.string cannot cast java.lang.long @ scala.runtime.boxesruntime.unboxtolong(unknown source)

take @ marshalling/unmarshalling implemented in spray. may not need reinvent solution, , if do, can take @ their source see how they've implemented it.

spray's marshalling/unmarshalling similar object graph serialization , works more json there's additional inherent complexity within implementation.

you around manually parsing json , try lift-json.

lift-json closer json though through extract can operate similar spray's marshaller/unmarshaller.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -