copied the the same code but getting this error type arguments [_] do not conform to trait MetaMapper's type parameter bounds [A <: net.liftweb.mapper.Mapper[A]] TravelMerchantTest/src/main/ scala/com/vtech/travelmerchant/snippet default.scala line 142 1239284830763 85593
Actually I am trying to make the JSON object using a mapper object. My function is this : def getJSONStringGeneric(anyObject :Any):NodeSeq = { //Console.println("anyObject.getClass :::::::: "+anyObject.getClass); //Console.println("anyObject.getClass.getName :::::::: "+anyObject.getClass.getName); //var objTemp = anyObject.asInstanceOf[MetaMapper [TestGearLogin]]; var sJSONString = "{\"bindings\": ["; anyObject match { case mm: MetaMapper[_] => mm.findAll.map( (userdetails: Mapper[_]) =>{ var tempJSON = ""; val ret = new StringBuilder ret.append("{") ret.append(userdetails.getSingleton.appendFieldToStrings (userdetails)) ret.append("}") // ret will be like {username=222,password=222,audit_dt=2009-04-06 00:00:00.0,login_pid=26} tempJSON = ret.toString(); tempJSON = tempJSON.replaceAll("\\{","\\{\""); tempJSON = tempJSON.replaceAll("\\}","\"\\}"); tempJSON = tempJSON.replaceAll("=","\":\""); tempJSON = tempJSON.replaceAll("," , "\",\""); tempJSON += ","; sJSONString +=tempJSON } ) } sJSONString = sJSONString.substring(0,sJSONString.length-1); // for slicing the last comma sJSONString += "]}"; Text(sJSONString); } but not getting a way of doing this. Please advise. Thanks Amit Kumar Verma On Apr 9, 6:14 pm, David Pollak <feeder.of.the.be...@gmail.com> wrote: > Howdy, > Scala is a static language, so the class for casting must be known at > compile time. It's not possible to construct a String at runtime and cast > an object into a class represented by that String. > > However, casting to a known class is easy in Scala... and it's done > primarily using pattern matching. The following code: > > def foo(in: Any) = in match { > case mm: MetaMapper[_] => > mm.findAll.map( > (m: Mapper[_]) => > m.asJs > ) > case _ => > } > > Does what I think you want. It takes an incoming instance, in and matches > it against being an instance of MetaMapper[_]. This means its some type of > MetaMapper (we don't know or care what the type parameter is). If it is a > MetaMapper, it's assigned to the mm variable. We can then call findAll on > that variable and we have a bunch of Mapper[_] instances. Note that I > explicitly called out the type of m in the function, but that line could be > re-written mm.findAll.map(m => m.asJs) because the compiler infers the type > of m. > > Does this help? > > Thanks, > > David > > On Thu, Apr 9, 2009 at 3:55 AM, Amit Kumar Verma <cdac.a...@gmail.com>wrote: > > > > > > > Hi All, > > > I am trying to type cast an scala object to its mapper object > > > 1 def getJSONString(anyObject :Object):NodeSeq = { > > > 2 var obj = anyObject.asInstanceOf[anyObject.getClass > > ().getName()]; > > > 3 obj.findAll.map(userdetails => { > > // some code will go here > > } > > Text("any string") > > } > > > but i am getting erroe as "expected [ but found (" on line 2. > > > please help me to typecast the object to its mapper object. > > > Thanks > > Amit Kumar Verma > > -- > Lift, the simply functional web frameworkhttp://liftweb.net > Beginning Scalahttp://www.apress.com/book/view/1430219890 > Follow me:http://twitter.com/dpp > Git some:http://github.com/dpp --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---