[play-json] Json.parse should return a 'safe' result

44 views
Skip to first unread message

Glenn/devalias

unread,
Apr 23, 2015, 7:59:44 PM4/23/15
to play-fram...@googlegroups.com
Heya,

So I noticed that currently Json.parse() will throw an exception on invalid data instead of a 'safe' result like most other places in the lib.

It would make more sense to me to return either a JsResult, or at the very least a Try[JsValue]/similar. Obviously the latter is trivial to do currently at an application level.

Given it's just wrapping Jackson, the current exception (I believe) would be http://jackson.codehaus.org/0.9.9/javadoc/org/codehaus/jackson/JsonParseException.html

This includes http://jackson.codehaus.org/0.9.9/javadoc/org/codehaus/jackson/JsonLocation.html but i'm not sure if that would be sufficient to faithfully fill the 'path' part of a JsResult.

What do you guys think?

- Glenn / devalias

Pascal Voitot Dev

unread,
Apr 24, 2015, 2:37:22 AM4/24/15
to Glenn/devalias, play-fram...@googlegroups.com
Hi,

As you said, it's very easy to manage at app level as long as it is well documented that it can throw an exception.
Actually, I believe you can't change this API because it's used in many existing apps and changing it would break them.
You could add a Json.parseSafe if you really want it...

Pascal

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

Naftoli Gugenheim

unread,
Apr 26, 2015, 1:24:50 PM4/26/15
to Glenn/devalias, play-fram...@googlegroups.com

+("100".toInt)


--
Reply all
Reply to author
Forward
0 new messages