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

Parse empty string as None with Json4s

I know Json4s handles Options on its own and most of the time this works great - for Option[T] it serializes None to missing value and reads missing value as None while automatically using the correct serializer/deserializer for T otherwise. My…
Ian
  • 5,704
  • 6
  • 40
  • 72
0
votes
2 answers

json4s IndexOutOfBoundsException when deserialising json String

I am trying to deserialise a simple json string using jackson json4s. I have been able to get this to work in scala 2.11, but on the upgrade to 2.12, I am seeing this error: import org.json4s._ import org.json4s.jackson.Serialization.read …
Nirmie
  • 65
  • 1
  • 4
0
votes
1 answer

deserializing json4s with generic type

Update: Looked closer into the rest of my code and I had an issue elsewhere which is why it was not working. Thanks I wanted to know if one can use json4 serializer to deserialize and object that uses generic. My json data has similar traits with…
nrvaller
  • 353
  • 6
  • 18
0
votes
0 answers

How to create own decoder for custom error handling?

I have created custom errors in my app: sealed trait DataError extends Product with Serializable final case class DataNotFound(ex: String) extends DataError final case class DataStorageError(ex: String) extends DataError And I have created simple…
Developus
  • 1,400
  • 2
  • 14
  • 50
0
votes
0 answers

How to validate JSON-string while parsing it?

I use the JSON4S library in Scala to do some parsing of serialised JSON strings to objects to have a simple JSON validator. case class MyObject ( productName: Option[String], amount: Int, price: Double ) def jsonCheck[T](data:…
Hans73
  • 21
  • 2
0
votes
0 answers

Json4s throwing error during json extraction after jar upgradation

I am trying to upgrade the scala version from 2.11.7 to 2.11.12. And I am also upgrading following dependencies json4s-core :: 3.5.0 -> 3.5.3 json4s-native :: 3.5.0 jackson-databind :: 2.10.1 But whenever I am trying to use the "extract"…
Bharath
  • 39
  • 3
0
votes
1 answer

MappingException: unknown error using json4s

I'm trying to parse a simple Json using json4s, and am finding that it will work in the Main class of my program, but for some reason not in the unit test. Here's a minimal example: build.sbt: ThisBuild / scalaVersion := "2.13.2" lazy val…
Chris J Harris
  • 1,597
  • 2
  • 14
  • 26
0
votes
1 answer

Json4s custom Serializer doesn't work due to type mismatch

I have a case class containing a field of password. For safety I need to mask it when converting to Json. So I create a custom serializer for this, as below. import org.json4s.CustomSerializer import org.json4s._ import…
user6502167
  • 731
  • 9
  • 18
0
votes
1 answer

Json4s DefaultFormats: Exception in thread "main" java.lang.AbstractMethodError

Reference: a test case from the official documentation. Currently, I use 3.5 json4s object JsonLoader { def parseJsonConfig[T: Manifest](filename: String): T = { implicit lazy val formats: DefaultFormats = new DefaultFormats { override val…
Daniel Chepenko
  • 2,229
  • 7
  • 30
  • 56
0
votes
1 answer

json to scala case class

I am trying to read the below json into scala case class. I am able to bind the case class to json using json4s. The problem is the expectedTypes would change for every table. It could be more or less number of elements and the name would be…
rakesh jayaram
  • 63
  • 1
  • 10
0
votes
2 answers

Json4s unable to desrialize in scala

I need a help in json desrialization in scala using Json4s. I get the following error when I try to desrialize the json scala.collection.immutable.Map$Map1 cannot be cast to LocationServiceTest$$anonfun$1$LocationList$3 …
Saawan
  • 363
  • 6
  • 24
0
votes
1 answer

Error when shading json4s-native in simple Scala project: "Symbol 'term org.json4s' is missing from the classpath."

I have a simple Scala project where I'd like to shade json4s-native before compiling my fat JAR using sbt-assembly. The idea is that in my own code, I would then import the shaded Java classes as follows. import…
Ivan Gozali
  • 2,089
  • 1
  • 27
  • 25
0
votes
1 answer

Scala context bounds "imitation" for abstract type parameters

I need to parse a json into a couple possible case classes: trait Request {...} case class RequestOne(...) extends Request case class RequestTwo(...) extends Request I created a request wrapper: trait RequestModel { type T <: Request def…
Martee
  • 77
  • 10
0
votes
1 answer

JSON4S not able to deserialize object

I have one class which extends a trait as shown below: case class Phone(number: String) trait Person { def name: String def phones: Seq[Phone] } case class Employee(name: String, phones: Seq[Phone] = Seq.empty) extends Person As shown above,…
Shekhar
  • 11,438
  • 36
  • 130
  • 186
0
votes
1 answer

NoSuchMethodError: org.json4s.FieldSerializer.

Spark version - 2.4.0 Scala version - 2.11.1 json4s version - 3.5.3 Getting error - Caused by: java.lang.NoSuchMethodError: org.json4s.FieldSerializer.(Lscala/PartialFunction;Lscala/PartialFunction;Lscala/reflect/Manifest;)V import…
Vijayant
  • 612
  • 2
  • 6
  • 17