Questions tagged [spray-json]

Relates to the spray-json Scala library.

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

339 questions
0
votes
1 answer

How to construct a case class for this json input and convert it to an object?

I get this Json string from a web api: {"results":{"Inne":"23.3","Ute":"5.8"}} How do I construct a case class to match this output? This is my attempt: case class Results(Inne: String, Ute: String) object MyJsonProtocol extends…
J. Busk
  • 17
  • 4
0
votes
1 answer

Reading/Writing None values as null with ReactiveMongo

We are in the process of migrating an existing REST service from Spring/Java to Spray using ReactiveMongo. One of the requirements for the migration (the first phase of it anyway), is that all inputs and outputs must match the current system. The…
TheIcemanCometh
  • 1,055
  • 2
  • 17
  • 31
0
votes
1 answer

Creating json having different keys and values with spray

My requirement is creating a json like "filters":{           "key1":"value1",         "key2":"Value2",         "key3":"Value3", .........      }, Here the all the keys and values name are different. i.e.keys are not fixed type.Also the number…
user1548787
  • 101
  • 1
  • 1
  • 8
0
votes
1 answer

Scala, Spray - Unmarshalling to List[Int]

I'm trying to get list of ints [1,2,3,...] from JSON api but I see conversion to generic type isn't working and Spray documentation is only showing unmarshalling to specific object. Any ideas how to make it work / what to google to get my…
0
votes
1 answer

using Either to parse failure and success

I'm trying to merge a Github pull request using spray. Github's API will return different values depending on whether it succeeds or fails. How do I parse that into an Either? Using the following imports: import akka.actor.ActorSystem import…
dvmlls
  • 2,206
  • 2
  • 20
  • 34
0
votes
1 answer

Spray Marshalling Custom Objects

I'm trying to marshal some custom objects to JSON in one of my responses and can't seem to get the logic right. I suspect this is a straight forward issue, but I just can't seem to find the solution anywhere. I have the following which is…
fatlog
  • 1,182
  • 2
  • 14
  • 28
0
votes
2 answers

Spray : How to Unmarshal a response of JsArray or JsObject (ie JsValue) in pipeline

I am creating a service that aggregates data and will need to be able to read any unknown JSON document. I have the pipeline defined as follows: private def pipeline = ( addHeader("Accept", "application/json") ~> sendReceive ~>…
Eric
  • 127
  • 7
0
votes
1 answer

Specs2 - Ignoring properties in a matcher with Future of a set of results

I have the following this matcher: def haveBodyWith[T: TypeTag: Unmarshaller](content: T)(implicit await: Duration): Matcher[Future[HttpResponse]] = { ===(content) ^^ { (f: Future[HttpResponse]) => { Await.result(f, await).entity.as[T].right.get…
anatolyr
  • 217
  • 1
  • 10
0
votes
1 answer

how to serialize Scala Array of types to JSON array in HTTP response using Spray?

I am a Spray newby, somewhat proficient in Scala, and although the Spray documentation is overall very good, I can't find any relevant example for my problem. I am trying to do something very simple: serialize (or Marshall) a Scala Array of my…
scott
  • 1
0
votes
1 answer

Spray-Json java.lang.OutOfMemoryError when calling parseJson

I'm using spray-json 1.3.0. I have a simple piece of Json that I am asking spray to parse, here it is import org.scalatest.{FlatSpec, MustMatchers} import spray.json._ class BlockCypherOutputMarshallerTest extends FlatSpec with MustMatchers { …
Chris Stewart
  • 1,641
  • 2
  • 28
  • 60
0
votes
1 answer

Spray JSON root object reader as array or object

I have domain model like: sealed trait MyTrait case class MyObject(a: String) extends MyTrait case class MyArray(a: Seq(MyObject)) extends MyTrait Example usages would look like: // array [{"a": "foo"}, {"a": "bar"}] //object {"a": "foobar"} I…
zmeda
  • 2,909
  • 9
  • 36
  • 56
0
votes
1 answer

Unable to find JSONReader for parameterised-typed custom class in test, despite import

I have a custom class as follows object SafeList { def apply[A](x: List[A]): SafeList[A] = if (x == null) EmptyList else HasItems[A](x) } sealed abstract class SafeList[+A] extends Product with Serializable { def get: List[A] } final case…
moncheery
  • 333
  • 4
  • 17
0
votes
1 answer

Scala for comprehension and options

I'm using Scala / Slick 3.1 (This is all through the spray-slick-swagger typesafe activator) and have 4 different queries running that I want to return as one object. I'm trying to compose all the futures together into one future. It works, but the…
bonez
  • 685
  • 1
  • 16
  • 39
0
votes
2 answers

Extract Json from Spray POST as string, not by marshaling to entity

There is an existing question that has much of what I'm after: Extracting Raw JSON as String inside a Spray POST route But it stops short without explaining how to get the actual Json string representation out of the Directive[String]. I'm trying to…
Richard Walker
  • 187
  • 1
  • 2
  • 11
0
votes
1 answer

Can't resolve symbol respondWithMediaType - Scala/Spray/Json

For some reason, my code wont resolve this symbol "respondWithMediaType" despite having all necessary imports. I'm fairly new to both spray and scala - so perhaps missing something obvious? import spray.http.MediaTypes._ import spray.json._ …