Questions tagged [play-json]

The play.api.libs.json package contains data structures for representing JSON data and utilities for converting between these data structures and other data representations.

The play.api.libs.json package contains data structures for representing JSON data and utilities for converting between these data structures and other data representations. It includes the following types:

  • JsString
  • JsNumber
  • JsBoolean
  • JsObject
  • JsArray
  • JsNull
313 questions
2
votes
1 answer

Play JSON library and sbt assembly merge error

Even with a simple Hello program, if I add the play-json as a library dependency in the build.sbt file, I always get the an merge error when I execute the 'assembly' command in sbt (sbt-assembly plugin). [error] stack trace is suppressed; run last…
2
votes
1 answer

How to update JSON with arrays of objects?

I'm trying to make a transformation to every object in an array in my JSON. The JSON looks something like this: { "foos": [ { "urls": ["www.google.com", "www.google.com", "www.stackoverflow.com"] }, { "urls":…
Billzabob
  • 33
  • 1
  • 3
2
votes
1 answer

Scala Play readNullable can't read Map types

I am trying to use play.api.lib.json to convert a json to my object. But then this happend... case class Foo(foo:Option[Map[String,String]]) case class Bar(bar:String,foo:Foo) def barJsonToModel(foobarJson:JsValue):Bar = { implicit val…
2
votes
2 answers

Play Framework: No implicit format for Map

Using Play 2.5 I cannot seem to serialize a Map[SomeCaseClass, String] case class SomeCaseClass(value: String) implicit val formatSomeCaseClass = Json.format[SomeCaseClass] Json.toJson(Map[SomeCaseClass, String](SomeCaseClass("") -> "")) Errors…
Eduardo
  • 6,900
  • 17
  • 77
  • 121
2
votes
1 answer

Difference between validate and validateOpt in JsValue

JsValue has two methods def validate[A](implicit rds: Reads[A]): JsResult[A] - Tries to convert the node into a JsResult[T] (Success or Error). def validateOpt[A](implicit rds: Reads[A]): JsResult[Option[A]] - I suppose it also does the same…
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184
2
votes
1 answer

Exclude certain fields during serialization using play-json-extensions

I have a case class that is having more than 22 parameters and to serialize this case class I am using json-play-extension. Pseudo code is as follows case class Foo(a1: Int,a2: Int,a3: Int,...,a24: Int) I have an implicit for Foo as…
Chaitanya
  • 3,590
  • 14
  • 33
2
votes
1 answer

Parse `NaN` Json.parse configuration

I am trying to parse a JSON object with a NaN using play-json in Scala. import play.api.libs.json._ val s = """{"a": NaN}""" val p = Json.parse(s) This errors with com.fasterxml.jackson.core.JsonParseException: Non-standard token 'NaN': enable…
armundle
  • 1,149
  • 2
  • 15
  • 28
2
votes
1 answer

Play-json 2.7.1: java.lang.NoSuchMethodError

After upgrading play-json to 2.7.0 I've started facing a runtime error: [info] com.mycompany.controllers.HealthControllerSpec *** ABORTED *** [info] java.lang.NoSuchMethodError:…
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
2
votes
1 answer

scala play json reads for a seal trait or enum type object

I have the following scala code with sealed traits and case objects. sealed trait StudentType { val studentLevel: String val code: Int } case object UnderGradFull extends StudentType { val studentLevel = "UGF" val code = 11 } case object…
vkt
  • 1,401
  • 2
  • 20
  • 46
2
votes
1 answer

Using an Enumeratum Enum in a Map does not work

I have an Enumeration created with enumeratum: sealed trait Language extends EnumEntry object Language extends Enum[Language] with PlayInsensitiveJsonEnum[Language] { val values: IndexedSeq[Language] = findValues case object DE extends…
pme
  • 14,156
  • 3
  • 52
  • 95
2
votes
2 answers

JsValue filter out null values

I am trying to figure out how to avoid null values. My problem is, that I am querying an API and it returns a null value. Here's an example: import play.api.libs.json._ case class InnerExample(value: String) object InnerExample { def…
SomeStranger314
  • 327
  • 1
  • 3
  • 12
2
votes
1 answer

scala-play 2.4.11, is it possible to desearialize Map with case class as key?

I'm trying to deal with play-json and it doesn't go well. Here are my case classes sealed case class Items(items: List[Item]) sealed case class Item(path: String, itemCounters: Map[ItemCategory, Long]) sealed case class ItemCategory(repository:…
Capacytron
  • 3,425
  • 6
  • 47
  • 80
2
votes
1 answer

Json object to map

Hello I would like to transform json object into map using implicit Reads. With the code below I run into a StackOverflow error, any one could see what the problem is : "pass": { "key-1": { "field1": "aaaa", "field2": "aaaa" }, …
jerome
  • 2,029
  • 4
  • 38
  • 58
2
votes
0 answers

Eclipse - Scala - Play - Macro Expansion error

I have defined play json Read on certain case classes object AccDataResponse { implicit val AccDataReads = Json.reads[Account] //compile error here } I am getting following warning on line Json.reads[Account] in eclipse ide with scala plugin.…
nir
  • 3,743
  • 4
  • 39
  • 63
2
votes
3 answers

Deserialize JSON distinguising missing and null values

I have a requirement to parse a JSON object, using play-json and distinguish between a missing value, a string value and a null value. So for example I might want to deserialize into the following case class: case class MyCaseClass( a:…
iandotkelly
  • 9,024
  • 8
  • 48
  • 67
1 2
3
20 21