Problem parsing null values in json

已查看 38 次
跳至第一个未读帖子

Thomas Fisher

未读,
2015年3月26日 17:46:412015/3/26
收件人 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

未读,
2015年3月26日 20:52:562015/3/26
收件人 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
回复全部
回复作者
转发
0 个新帖子