Questions tagged [spray-json]

Relates to the spray-json Scala library.

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

327 questions
19
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
  • 12,534
  • 20
  • 79
  • 134
18
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
  • 3,897
  • 4
  • 21
  • 32
17
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
  • 15,505
  • 11
  • 62
  • 86
12
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
  • 173
  • 1
  • 2
  • 7
12
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,454
  • 6
  • 25
  • 41
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
  • 28,098
  • 11
  • 88
  • 150
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
  • 240
  • 3
  • 12
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
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,022
  • 2
  • 21
  • 38
9
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,212
  • 9
  • 45
  • 77
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,029
  • 2
  • 11
  • 35
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
  • 953
  • 6
  • 14
8
votes
2 answers

Spray-Json: How to parse a Json Array?

I'm new to the Spray-Json API and I'm trying to parse a Json response from the Docker REST API. There is a clean example of the usage of Spray-Json to parse this Google Map Json response : { "results" : [ { "elevation" :…
abronan
  • 3,003
  • 4
  • 26
  • 37
7
votes
2 answers

spray-json failing for Seq of Eithers

Not sure this is a bug, but the following demo fails on the final cases: import spray.json._ import DefaultJsonProtocol._ object SprayTest { 1.toJson "".toJson (Left(1): Either[Int, String]).toJson (Right(""): Either[Int, String]).toJson …
acjay
  • 28,690
  • 4
  • 51
  • 93
1
2 3
21 22