Created
July 8, 2013 20:13
-
-
Save levinotik/5952093 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| case class GoogleApiResult[T](status: String, results: List[T]) | |
| case class AddressComponent(longName: String, shortName: String, types: List[String]) | |
| case class Location(lat: Double, lng: Double) | |
| case class Bounds(northeast: Location, southwest:Location) | |
| case class Viewport(northeast: Location, southwest:Location) | |
| case class Geometry(bounds: Bounds, location: Location, locationType: String, viewport: Viewport) | |
| object MyJsonProtocol extends DefaultJsonProtocol { | |
| implicit val locationFormat = jsonFormat2(Location) | |
| implicit val boundsFormat = jsonFormat2(Bounds) | |
| implicit val viewportFormat = jsonFormat2(Viewport) | |
| implicit val geometryFormat = jsonFormat4(Geometry) | |
| implicit def googleApiResultFormat[T :JsonFormat] = jsonFormat2(GoogleApiResult.apply[T]) | |
| } | |
| val someJsonString = """{ | |
| "results": [ | |
| { | |
| "address_components": [ | |
| { | |
| "long_name": "11691", | |
| "short_name": "11691", | |
| "types": [ | |
| "postal_code" | |
| ] | |
| }, | |
| { | |
| "long_name": "Far Rockaway", | |
| "short_name": "Far Rockaway", | |
| "types": [ | |
| "neighborhood", | |
| "political" | |
| ] | |
| }, | |
| { | |
| "long_name": "FAR ROCKAWAY", | |
| "short_name": "FAR ROCKAWAY", | |
| "types": [ | |
| "locality", | |
| "political" | |
| ] | |
| }, | |
| { | |
| "long_name": "New York", | |
| "short_name": "NY", | |
| "types": [ | |
| "administrative_area_level_1", | |
| "political" | |
| ] | |
| }, | |
| { | |
| "long_name": "United States", | |
| "short_name": "US", | |
| "types": [ | |
| "country", | |
| "political" | |
| ] | |
| } | |
| ], | |
| "formatted_address": "FAR ROCKAWAY, NY 11691, USA", | |
| "geometry": { | |
| "bounds": { | |
| "northeast": { | |
| "lat": 40.61421800000001, | |
| "lng": -73.73799679999999 | |
| }, | |
| "southwest": { | |
| "lat": 40.5884689, | |
| "lng": -73.7894708 | |
| } | |
| }, | |
| "location": { | |
| "lat": 40.6024346, | |
| "lng": -73.762495 | |
| }, | |
| "location_type": "APPROXIMATE", | |
| "viewport": { | |
| "northeast": { | |
| "lat": 40.61421800000001, | |
| "lng": -73.73799679999999 | |
| }, | |
| "southwest": { | |
| "lat": 40.5884689, | |
| "lng": -73.7894708 | |
| } | |
| } | |
| }, | |
| "types": [ | |
| "postal_code" | |
| ] | |
| } | |
| ], | |
| "status": "OK" | |
| }""" | |
| someJsonString.toJson.convertTo[GoogleApiResult[Geometry]] | |
| java.lang.AbstractMethodError: MyJsonProtocol$.jsonFormat2(Lscala/Function2;Lspray/json/JsonFormat;Lspray/json/JsonFormat;Lscala/reflect/ClassTag;)Lspray/json/RootJsonFormat; | |
| at MyJsonProtocol$.<init>(<console>:24) | |
| at MyJsonProtocol$.<clinit>(<console>) | |
| at .<init>(<console>:29) | |
| at .<clinit>(<console>) | |
| at .<init>(<console>:7) | |
| at .<clinit>(<console>) | |
| at $print(<console>) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
| at java.lang.reflect.Method.invoke(Method.java:597) | |
| at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) | |
| at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) | |
| at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) | |
| at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) | |
| at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) | |
| at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745) | |
| at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790) | |
| at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702) | |
| at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566) | |
| at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573) | |
| at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576) | |
| at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867) | |
| at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822) | |
| at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822) | |
| at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) | |
| at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822) | |
| at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:889) | |
| at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
| at java.lang.reflect.Method.invoke(Method.java:597) | |
| at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:73) | |
| at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:64) | |
| at sbt.Console.console0$1(Console.scala:23) | |
| at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24) | |
| at sbt.TrapExit$.executeMain$1(TrapExit.scala:33) | |
| at sbt.TrapExit$$anon$1.run(TrapExit.scala:42) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment