Questions tagged [spray-json]

Relates to the spray-json Scala library.

spray-json is a lightweight, clean and simple implementation in .

339 questions
20
votes
2 answers

Serialize Map[String, Any] with spray json

How do I serialize Map[String, Any] with spray-json? I try val data = Map("name" -> "John", "age" -> 42) import spray.json._ import DefaultJsonProtocol._ data.toJson It says Cannot find JsonWriter or JsonFormat type class for…
Yaroslav
  • 4,543
  • 5
  • 26
  • 36
20
votes
2 answers

how to serialize case classes with traits with jsonspray

I understand that if I have: case class Person(name: String) I can use object PersonJsonImplicits extends DefaultJsonProtocol { implicit val impPerson = jsonFormat1(Person) } and thus serialize it with: import…
Jas
  • 14,493
  • 27
  • 97
  • 148
18
votes
6 answers

How to represent optional fields in spray-json?

I have an optional field on my requests: case class SearchRequest(url: String, nextAt: Option[Date]) My protocol is: object SearchRequestJsonProtocol extends DefaultJsonProtocol { implicit val searchRequestFormat = jsonFormat(SearchRequest,…
François Beausoleil
  • 16,265
  • 11
  • 67
  • 90
14
votes
1 answer

Cannot find an implicit ExecutionContext. You might pass spray scala

I have this two erros: Error:(39, 20) Cannot find an implicit ExecutionContext. You might pass an (implicit ec: ExecutionContext) parameter to your method or import scala.concurrent.ExecutionContext.Implicits.global. val pipeline = sendReceive …
kam kimo
  • 193
  • 1
  • 2
  • 7
14
votes
7 answers

Get JSON object from AJAX call

I'm new to AJAX and javascript. In my project, I have to get a json object in my javascript file. I've used spray-json and it shows me the json object in the url. http://localhost:8081/all-modules { "status": "S1000", "description": "Success", …
Shashika
  • 1,606
  • 6
  • 28
  • 47
11
votes
1 answer

Explanation for - No Reflection involved

I have a very simple question. This is not only true with spray-json but I have read similar claims with argonaut and circe. So please enlighten me. In spray-json, I have come across the statement saying There is no reflection involved. I understand…
Jatin
  • 31,116
  • 15
  • 98
  • 163
11
votes
1 answer

How to expose REST service for JSON?

I need to expose a Spray service that accepts JSON payload. Where can I find a sample that would demonstrate such a feature?
Giri
  • 235
  • 4
  • 14
10
votes
3 answers

Spray-json deserializing nested object

How to deserialize nested objects correctly in spray-json? import spray.json._ case class Person(name: String) case class Color(n: String, r: Int, g: Int, b: Int, p: Person) object MyJsonProtocol extends DefaultJsonProtocol { …
user3103600
  • 173
  • 1
  • 2
  • 5
10
votes
1 answer

spray-json cannot marshal Map[String,String]

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…
ThaDon
  • 7,826
  • 9
  • 52
  • 84
10
votes
3 answers

spray-json and list marshalling

I'm using spray-json to marshal lists of custom objects into JSON. I have the following case class and its JsonProtocol. case class ElementResponse(name: String, symbol: String, code: String, pkwiu: String, remarks: String, priceNetto: BigDecimal,…
Marcin Cylke
  • 2,100
  • 2
  • 21
  • 40
9
votes
1 answer

Customizing JSON object property names with Spray JSON

I'm using spray-json to serialize an object tree, which is based on a class hierarchy such as this: trait Base { val _id: Long } case class Person(_id: Long, firstName: String, lastName: String) extends Base case class Company(_id: Long, name:…
yby
  • 915
  • 1
  • 8
  • 24
9
votes
3 answers

spray-json JsString quotes on string values

I am using json-spray. It seems that when I attempt to print a parsed JsString value, it includes book-ended quotes on the string. val x1 = """ {"key1": "value1", "key2": 4} """ println(x1.asJson) println(x1.asJson.convertTo[Map[String,…
Ben Schmidt
  • 261
  • 2
  • 13
9
votes
1 answer

Convert polymorphic case classes to json and back

I am trying to use spray-json in scala to recognize the choice between Ec2Provider and OpenstackProvider when converting to Json and back. I would like to be able to give choices in "Provider", and if those choices don't fit the ones available then…
wernerb
  • 105
  • 1
  • 5
8
votes
2 answers

Scala, spray-json: universal enumeration json formatting

I have such model: two enumerations and one case class with two fields of these enums types: // see later, why objects are implicit implicit object Fruits extends Enumeration { val Apple = Value("apple") val Orange = Value("orange") } implicit…
Evgeny Veretennikov
  • 3,889
  • 2
  • 16
  • 36
8
votes
1 answer

How does Scala use explicit types when resolving implicits?

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…
MrProper
  • 1,023
  • 7
  • 14
1
2 3
22 23