Questions tagged [json4s]

A single AST to be used by other scala json libraries

At this moment there are at least 6 json libraries for scala, not counting the java json libraries. All these libraries have a very similar AST. This project aims to provide a single AST to be used by other scala json libraries.

At this moment the approach taken to working with the AST has been taken from lift-json and the native package is in fact lift-json but outside of the lift project.

https://github.com/json4s/json4s

449 questions
9
votes
1 answer

Fail-fast json4s serialisation of sealed trait and object enum when missing serializer

Set up I'm using json4s 3.2.11 and Scala 2.11. I have an enumeration defined using sealed trait, and a custom serializer for it: import org.json4s.CustomSerializer import org.json4s.JsonAST.JString import org.json4s.DefaultFormats import…
huon
  • 94,605
  • 21
  • 231
  • 225
9
votes
2 answers

Deserialization of case object in Scala with JSON4S

I have some case classes defined like follows: sealed trait Breed case object Beagle extends Breed case object Mastiff extends Breed case object Yorkie extends Breed case class Dog(name: String, breed: Breed) I also have an endpoint defined with…
user2066880
  • 4,825
  • 9
  • 38
  • 64
9
votes
3 answers

NotSerializableException with json4s on Spark

Basically, i have to analyze some complex JSON's on HDFS with Spark. I use "for comprehensions" to (pre)filter the JSON's and "extract" method of json4s to wrap it into a case class This one works fine! def foo(rdd: RDD[String]) = { case class…
λ Allquantor λ
  • 1,071
  • 1
  • 9
  • 22
9
votes
1 answer

Serialize and Deserialize scala enumerations or case objects using json4s

Suppose I have an enumeration or sealed group of case objects as follows: sealed abstract class Status case object Complete extends Status case object Failed extends Status case object Pending extends Status case object Unknown extends…
jonderry
  • 23,013
  • 32
  • 104
  • 171
9
votes
3 answers

How to Manipulate JSON AST in Scala

I am experimenting with the json4s library (based on lift-json). One of the things I would like to do is to parse a JSON string into an AST, and then manipulate it. For example, I would like to upsert a field (insert the field into the AST if it…
Eduardo
  • 8,362
  • 6
  • 38
  • 72
8
votes
2 answers

How to iterate org.json4s.JsonAST.JValue which is an array of JSON objects to separately work on each object in Scala?

I have a sample array: [{ "abc":"1", "de":"1" }, { "fgh":"2", "ij":"4" }] which is a org.json4s.JsonAST.JValue. How is it possible to iterate over each object inside the array, to operate on each object separately?
GKVM
  • 335
  • 1
  • 5
  • 17
8
votes
2 answers

Json4s custom serializer with unordered fields

In the example given on the json4s readme https://github.com/json4s/json4s#serializing-non-supported-types the match only works if the fields are order {"start":0,"end":0}. If the start and end fields are swapped then the match doesn't work. Is…
Benjamin
  • 727
  • 1
  • 9
  • 19
7
votes
2 answers

spark 2.1.1 : Parsed JSON values do not match with class constructor

I've a strange problem with spark 2.1.1 and json4s.jackson. I upgraded my streaming project from spark 1.5.1. Now when I execute code in IDE everything works fine. But after assembly and code standalone execution with spark-submit I got the…
Toren
  • 6,648
  • 12
  • 41
  • 62
7
votes
1 answer

json4s: Deserializing specific fields with a custom serializer

I have a case class with many members, two of which are non-primitive: import com.twitter.util.Duration case class Foo( a: Int, b: Int, ..., y: Int, z: Int, timeoutSeconds: Duration, runtimeMinutes: Duration) I'd like to deserialize…
kenrose
  • 186
  • 1
  • 5
7
votes
1 answer

Different routes based on request content type Spray Routing 1.2.1

I would like to support a couple of different content types submitted to the same URL: e.g: application/x-www-form-urlencoded, multipart/form-data, application/json I would like to do something like: post { …
Sam in Oakland
  • 113
  • 1
  • 7
7
votes
2 answers

How can I rename a field during serialization with Json4s?

How to easily rename field-names in json4s? From their documentation, i've tried the following snippet but it doesn't seem to rename the serial field to id. case class Person(serial: Int, firstName: String) val rename =…
user3103600
  • 173
  • 1
  • 2
  • 5
6
votes
2 answers

JSON4S type hint does not work

The following test snippet implicit val formats = DefaultFormats + FullTypeHints(Contacts.classList) val serialized = Serialization.write(List(Mail(field = "random@mail.com", note = "Random…
Dyin
  • 5,815
  • 8
  • 44
  • 69
6
votes
2 answers

How do I generate pretty JSON with json4s?

This snippet of code works very well, but it generates compact JSON (no line breaks / not very human readable). import org.json4s.native.Serialization.write implicit val jsonFormats = DefaultFormats //snapshotList is a case class val jsonString:…
arosca
  • 469
  • 7
  • 15
6
votes
1 answer

SBT & Json4s serializing Joda Time: How can I access the .ext package?

In my Scala Spray.io application, I would like to turn some Joda LocalTime and LocalDate objects into JSON. This is apparently done by adding JodaTime support from Json4s to the DefaultFormats as follows: object Json4sProtocol extends Json4sSupport…
hanbzu
  • 880
  • 1
  • 8
  • 14
6
votes
1 answer

Parsing and manipulating json in Scala

I have this JSON that is returned from a REST-service I'm using. { "id": "6804", "signatories": [ { "id": "12125", "fields": [ { "type": "standard", …
Stefan Konno
  • 1,337
  • 2
  • 16
  • 28
1
2
3
29 30