bizzabo / play-json-extensions

+22 field case class formatter and more for play-json
http://cvogt.org/play-json-extensions/api/
Other
195 stars 47 forks source link

Option fields handling #13

Closed MrBan closed 8 years ago

MrBan commented 9 years ago

I've noticed a different behavior between jsonx format and standard json format when dealing with Option fields. In the example below, the first fromJson conversion returns a JsError while the second call returns JsSuccess. In my opinion the first behavior is the correct one since the JSON object is invalid.

This is relative to version 0.2. I know it is quite old, but if you could provide any clue on how to fix it I would really appreciate it :)

import org.cvogt.play.json.Jsonx
import play.api.libs.json._

case class C1(v: Option[String])
case class C2(v: Option[String])

implicit val c1JsonFormat = Json.format[C1]
implicit val c2JsonFormat = Jsonx.formatCaseClass[C2]

val json = Json.obj("v" -> 11)

Json.fromJson[C1](json)  // this returns JsError
Json.fromJson[C2](json)  // this returns JsSuccess

Thanks

cvogt commented 9 years ago

@MrBan thx, will look into it.

cvogt commented 9 years ago

haven't forgotten about this, trying to get to it very soon

MrBan commented 9 years ago

Thanks a lot :)

cvogt commented 8 years ago

So my investigations show that this magically got fixed in e95cd47, in the upgrade from play-json 2.3 to play-json 2.4. This was shortly before the 0.3.0 release. If I knew why this was broken and how to fix it, I would release a 0.2.1, but since the fix somehow came with play-json 2.4.1, I would suggest to upgrade to the latest play-json-extensions 0.6.0. Probably a good idea anyways :).

cvogt commented 8 years ago

Since it works since 0.3.0 I am closing this