Questions tagged [spray-json]

Relates to the spray-json Scala library.

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

339 questions
4
votes
0 answers

Convert nested case class to JSON using spray-json

If I have nested case classes, how can they be converted to JSON using spray-json? For example my structure looks something like: case class MyObj1(name: String, myObject2: MyObject2) case class MyObj2(myObjec3s: Seq[MyObj3]) case class…
bashan
  • 3,572
  • 6
  • 41
  • 58
4
votes
2 answers

spray-json serialization in spray-routing with custom JsonFormats

Using Spray with spray-json for a system, version: "io.spray" %% "spray-json" % "1.2.6" I cannot figure how to get custom JsonFormat definitions to work for serialization that is being handled by spray-routing. I've had two separate circumstances…
Rich
  • 2,805
  • 8
  • 42
  • 53
4
votes
3 answers

Spray client - treat response with unexpected content-type as application/json?

When I try to GET amazon identity data like that val pipeline: HttpRequest => Future[IdentityData] = sendReceive ~> unmarshal[IdentityData] pipeline(Get("http://169.254.169.254/latest/dynamic/instance-identity/document")) with appropriate case…
eugen-fried
  • 2,111
  • 3
  • 27
  • 48
4
votes
1 answer

Implicit FromRequestUnmarsharell not found

I am trying to use my domain objects as a request/response body parameters. I am using spray-routing and as[T] to unmarshall object. But constantly I'm getting could not find implicit value for parameter um:…
bkowalikpl
  • 817
  • 5
  • 11
4
votes
2 answers

Providing a JsonFormat for a Sequence of Objects

i`m trying here to find some help to apply an JsonFormat extended of the DefaultJsonProtocol to an class containing a Sequence of Objects. So for the classes: class Person(val name: String, [......], val adresses: Seq[Adress]) class Adress(val…
Klink
  • 145
  • 2
  • 11
4
votes
0 answers

Test spray.io response

I have the next code: //models case class Foo(name: String, age: Option[Int] = None) //routing trait FooRouting extends HttpService { def index(foos: List[Foo]): twirl.api.Html = html.foo.render(foos) val route = path("") { get…
lito
  • 989
  • 8
  • 21
4
votes
1 answer

how do i convert json with mixed type values to json with scala and json spray

I tried the tutorial of json spray but i have a different string where one value is a string and the other one is a list. How do i convert the following string into a json object where each key is either a list or a string? source = """{ "some":…
David Michael Gang
  • 7,107
  • 8
  • 53
  • 98
4
votes
1 answer

How can provide JsonFormats for case class that references itself?

How can provide JsonFormats for case class that references itself ? I'm following this guideline and wrote following code case class Item(name: String, desc: Option[String], prices: Array[String], subitems: Option[List[Item]]) import…
expert
  • 29,290
  • 30
  • 110
  • 214
4
votes
2 answers

Can't convert unicode symbols to cyrillic

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…
4lex1v
  • 21,367
  • 6
  • 52
  • 86
4
votes
1 answer

Scala type class pattern and generic methods

I'm trying to write a generic extractor for parsing json POST body using spray and spray-json. However I'm struggling to get it working with more than one model. Here's the case statement in the service object: import MyJsonProtocol._ ... def…
Russell
  • 12,261
  • 4
  • 52
  • 75
3
votes
1 answer

Parsing more than 22 fields with Spray Json without nesting case classes

I am trying to use Spray-JSON to marshall an incoming JSON with more than 22 fields. Since there is no JsonFormat23() method, I am having to nest my case classes to get around the limitation. However, the incoming JSON does not know of the nested…
Dennis
  • 415
  • 4
  • 13
3
votes
1 answer

What is the correct way to register generic type to spray-json-support in akka-http Scala?

So, I have this class: case class Something[T](data: Option[T] = None) And i register it like the instruction said in https://github.com/spray/spray-json and in https://doc.akka.io/docs/akka-http/current/common/json-support.html. Like this: import…
Enki Probo
  • 51
  • 6
3
votes
0 answers

Akka HTTP, Spray Json and Option Fields Failing as Required

I have a case class: case class OpcTagPlaybook(name: String, tags: Seq[OpcTagAtTime], looped: Boolean, enabled: Option[String]) With an optional enabled field that will contain a date. Spray Json describes encoding/decoding: implicit val…
JasonG
  • 5,794
  • 4
  • 39
  • 67
3
votes
1 answer

could not find implicit value for evidence parameter for implicit json formats

I am trying to simply create a json format for my case classes: case class ImageRequest (inputs: Array[ImageObject]) case class ImageObject(data: Data) case class Data(image: Image) case class Image(url: String) and here are the implicit…
ZDevelop94
  • 139
  • 2
  • 11
3
votes
2 answers

How to wrap an REST API client in an Actor

I'm trying to write an actor that calls an HTTP REST API. The rest API needs a query parameter that will be passed from the invoking Actor. The official documentation has an example to achieve the above using a preStart method that pipes the message…
MojoJojo
  • 3,897
  • 4
  • 28
  • 54