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
4
votes
1 answer

How can I parse a json and extract to different case classes depending of its content

I'm trying to parse different types of events in json format using json4s. I have written some case classes to represent the different events all inheriting from a base class Event: abstract class Event{ def EventType : String } case class…
amanya
  • 75
  • 6
4
votes
1 answer

Why does json4s need a Scala compiler as a runtime dependency

I've discovered that by using json4s native org.json4s json4s-native_2.10 3.2.9 brings scalap and scala-compiler…
david.perez
  • 6,090
  • 4
  • 34
  • 57
4
votes
1 answer

scala -- How to customize date format using SimpleDateFormat using json4s

I need a date format like Tue May 31 17:46:55 +0800 2011 And the current formats I am using is implicit val formats = Serialization.formats(NoTypeHints) It will produce : 2011-05-31 17:46:55.0 How can I make the formats that produce string…
jilen
  • 5,633
  • 3
  • 35
  • 84
3
votes
1 answer

json4s always escapes unicode character €

I try pretty-writing a JString containing a € character with json4s as follows: import org.joda.time.format.ISODateTimeFormat import org.joda.time.{DateTime, DateTimeZone} import org.json4s.native.Serialization.writePretty import…
llehmann
  • 31
  • 1
3
votes
2 answers

Trouble serializing optional value class instances with json4s

I'm trying to serialize a case class with optional value-class field to JSON using json4s. So far, I'm not able to get the optional value-class field rendered correctly (see the snippet below with examples). I tried json-native and json-jackson…
Roman
  • 64,384
  • 92
  • 238
  • 332
3
votes
0 answers

Json4s - extract to correct trait implementation based on kind property

I have a trait that has many implementations. When in json format you can distinguish easly between them by kind property. Is there a some simple way to have json4s pick correct implementation based on that property? I would prefer to avoid writing…
Gustek
  • 3,680
  • 2
  • 22
  • 36
3
votes
3 answers

Convert Json with variable keys

Am getting a JSON in { "segment": { "134": "34", "154": "342" } } all I am trying to do is map the keys as value i.e convert it into format like { "segment ": [{ "segmentationStrategyId ": 134, …
Vishal
  • 1,442
  • 3
  • 29
  • 48
3
votes
1 answer

Parsing string in json to java.time.LocalTime using json4s

How can I parse a string of YYYY-MM-dd to java.time.LocalDate? Currently I have tried the following approaches: import JavaTimeSerializers throws Error JString cannot be converted to LocalDate case class Dates(createdAt: LocalDate, updatedAt:…
vamsiampolu
  • 6,328
  • 19
  • 82
  • 183
3
votes
1 answer

What would be the best practice of Scala to have a method accept two different models

Currently I have a method that accept ModelA and know to perform actions on it. so in my controller I accept request of ModelA and call this method with it. And now, I want to be able to accept request of ModelB, map the request to be of ModelA…
jack miao
  • 1,398
  • 1
  • 16
  • 32
3
votes
1 answer

Deserializing to java objects with Scala and json4s

I have HTTP client written in Scala that uses json4s/jackson to serialize and deserialize HTTP payloads. For now I was using only Scala case classes as model and everything was working fine, but now I have to communicate with third party service.…
Mateusz Gruszczynski
  • 1,421
  • 10
  • 18
3
votes
1 answer

Json4s add JValue to JArray

I'm using scala and Json4s to add a JValue to a JArray in a loop, this way: var recordsJArray = JArray for (record <- recordsList) { val mrecord= new com.google.gson.Gson().toJson(record.asMap()) val jsonRecord =…
jsonH
  • 61
  • 6
3
votes
1 answer

json4s - parsing fails for simple String value

Why the encoding works for "bla-b" but not the parsing ? scala> import org.json4s._ import org.json4s._ scala> import org.json4s.native.JsonMethods._ import org.json4s.native.JsonMethods._ scala> import org.json4s.JsonDSL._ import…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
3
votes
1 answer

json4s org.json4s.package$MappingException: Do not know how to convert JString into double

I am trying a very simple example, but not able to make it work; Below is my JSON format, I am using the Scala json4s parser for parsing JSON; json4s fails to parse a JSON string if any JSON field is not a string. For example json4s fails to parse…
nilesh1212
  • 1,561
  • 2
  • 26
  • 60
3
votes
1 answer

How can I convert between play.api.libs.json.JsValue and org.json4s.JValue

I'm using Play Framework to build an API, but need to perform some validation and transformation operations with a library that only speaks Json4s. So far, the only thing I've been able to get to work is converting to a string and parsing with the…
Matt Miller
  • 3,501
  • 5
  • 27
  • 26
3
votes
1 answer

Can't extract simple JSON to case class with json4s

I'm trying to use json4s in a worksheet to try it out, I want simply to extract a json to some case class: import org.json4s.native.JsonMethods import org.json4s.{DefaultFormats, Extraction, JValue} case class Person(name: String, age: Int) val…
Joe
  • 2,543
  • 3
  • 25
  • 49