Problem parsing null values in json

38 views
Skip to first unread message

Thomas Fisher

unread,
Mar 26, 2015, 5:46:41 PM3/26/15
to play-fr...@googlegroups.com
Hi everyone. Having a problem with play.api.data.FormUtils. It seems to filter out nulls when turning JsValues into a map. For example:

scala> myJson
res30: play.api.libs.json.JsObject = {"tommy":"test","null":null}

scala> fromJson("", myJson)
res32: Map[String,String] = Map(tommy -> test)


    case JsNull => Map.empty

Does anyone have any recommendations?

James RopR

unread,
Mar 26, 2015, 8:52:56 PM3/26/15
to play-framework
Personally, I like to know when I get a value out of a map, that it's not going to be null, this is one thing that makes Scala maps so much better than Java maps.  Putting nulls into maps undermines this.

The json support in Play's form API is just a convenience so that you can share data types for forms and maps.  There's no such thing as a null in a form, so it gets ignored.  If you want to handle proper json data types, use Play's json Reads/Writes APIs.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James RopR
Software Engineer

Typesafe – Build reactive apps!
Twitter: @jroper
Reply all
Reply to author
Forward
0 new messages