spray-json

Deserializing a JSON dictionary

时光总嘲笑我的痴心妄想 提交于 2019-12-11 08:57:06
问题 Lots of headache here, how do I deserialize JSON like the one in the image? I'd usually see things like {"Word" : "Fish","Definition" : "It is an animal", etc} but the one I have found that is the closest thing to what I am looking for does not specify the value type, hence I can't really deserialize it with case classes. I'm sorry that I'd really prefer a clear explanation, I'm bad at this. I'm really looking forward to an answer, thank you for reading. 回答1: It would appear that you are

What is a good way to handle default values with spray-json

我的梦境 提交于 2019-12-08 19:55:37
问题 In some cases default values make more sense than optionals in case classes: case class Car(numberOfWheels:Int = 4, color:String) case class Car(numbeOfWheels:Option[Int], color:String) //silly In the first case I'd expect to be able to easily convert the following json to an instance: {"color":"red"} But with a standard jsonFormat2(Car) , spray-json complains about missing value for numberOfWheels . How do I work around this most cleanly? 回答1: I stumbled upon the same problem. I've create a

How does Scala use explicit types when resolving implicits?

烈酒焚心 提交于 2019-12-08 17:45:37
问题 I have the following code which uses spray-json to deserialise some JSON into a case class, via the parseJson method. Depending on where the implicit JsonFormat[MyCaseClass] is defined (in-line or imported from companion object), and whether there is an explicit type provided when it is defined, the code may not compile. I don't understand why importing the implicit from the companion object requires it to have an explicit type when it is defined, but if I put it inline, this is not the case?

Get Json Object using spray.json

∥☆過路亽.° 提交于 2019-12-07 12:59:31
问题 I'm using spray and I need to return a json object through a method. val route = path("all-modules") { get { respondWithMediaType(`text/html`) { complete( configViewer.findAllModules.toString) } } } This prints ConfigResults(S1000,Success,List(testDataTypes, mandate, sdp)) But I need get this as the json object. how can I do it? I tried in this way val route = path("all-modules") { get { respondWithMediaType(`application/json`) { complete{ configViewer.findAllModules } } } } It gives an

could not find implicit value for evidence parameter of type ^

为君一笑 提交于 2019-12-06 06:33:04
问题 I am trying to write a test for a Post request here is my code : val request = CreateLinkRequest(token = Some(validToken),billing_ref_id = Some("123"), store_id = Some("123"), agent_id = Some("123")) val endPoint = Uri(this.serverRootUrl + "path").toString val post = Post(endPoint, request) val pipeline = jsonAsStringPipeline(post) val responseContents = Await.ready(pipeline, atMost = callMaxWaitDuration) But this doesnt compile, I keep getting this error : Error:(156, 20) could not find

Can't convert unicode symbols to cyrillic

拜拜、爱过 提交于 2019-12-06 05:19:46
问题 I have a bunch of documents persisted in Apache Lucene with some names in russian, and when I'm trying to print them out it looks like this "\u0410\u0441\u043f\u0430\u0440" , but not in cyrillic symbols. The project is in Scala. I've tried to fix this with Apache Commons unescapeJava method, but it didn't help. Are there any other options? Updated: Project is writen with Spray framework and returns json like this. { "id" : 0, "name" : "\u0410\u0441\u043f\u0430\u0440" } 回答1: I'm going to try

spray-json cannot marshal Map[String,String]

心已入冬 提交于 2019-12-05 19:39:38
问题 I have the following route setup, but when my map is returned in the first complete block I get an error: could not find implicit value for evidence parameter of type spray.httpx.marshalling.Marshaller[scala.collection.immutable.Map[String,String]] import spray.routing.HttpService import akka.actor.Actor import spray.http.HttpRequest import spray.routing.RequestContext import spray.json.DefaultJsonProtocol._ class UserServiceActor extends Actor with RestUserService { def actorRefFactory =

Get Json Object using spray.json

喜你入骨 提交于 2019-12-05 18:22:22
I'm using spray and I need to return a json object through a method. val route = path("all-modules") { get { respondWithMediaType(`text/html`) { complete( configViewer.findAllModules.toString) } } } This prints ConfigResults(S1000,Success,List(testDataTypes, mandate, sdp)) But I need get this as the json object. how can I do it? I tried in this way val route = path("all-modules") { get { respondWithMediaType(`application/json`) { complete{ configViewer.findAllModules } } } } It gives an compilation error could not find implicit value for parameter marshaller: spray.httpx.marshalling

Cannot find JsonWriter or JsonFormat type class for a case class

自作多情 提交于 2019-12-05 07:42:56
Following the tutorial from http://www.smartjava.org/content/first-steps-rest-spray-and-scala , there are some unexpected error messages. What is going on? Have I defined implicit JsonWriter by the implicit val personFormat = jsonFormat3(Person) call? scala> import spray.json.DefaultJsonProtocol import spray.json.DefaultJsonProtocol scala> object MyJsonProtocol extends DefaultJsonProtocol { implicit val personFormat = jsonFormat3(Person) } | | defined object MyJsonProtocol scala> case class Person(name: String, fistName: String, age: Long) defined class Person scala> import spray.json._ import

Parsing a simple array with Spray-json

吃可爱长大的小学妹 提交于 2019-12-05 05:29:53
I'm trying (and failing) to get my head around how spray-json converts json feeds into objects. If I have a simple key -> value json feed then it seems to work ok but the data I want to read comes in a list like this: [{ "name": "John", "age": "30" }, { "name": "Tom", "age": "25" }] And my code looks like this: package jsontest import spray.json._ import DefaultJsonProtocol._ object JsonFun { case class Person(name: String, age: String) case class FriendList(items: List[Person]) object FriendsProtocol extends DefaultJsonProtocol { implicit val personFormat = jsonFormat2(Person) implicit val