Working on a Java and Scala code-base, there’s a debate about whether to use Java’s Jackson JSON or the Play Framework’s JSON Library.
After reading the Play JSON Docs, as well as Chapter 9 (JSON) of Play for Scala, I also ran through an example from Mykong on Jackson.
Based on looking at a few simple examples, Play’s JSON Library seems like the superior choice due to, overall, its Functional Programming Approach:
- Providing compile-time safety when parsing JSON with Option/JsResult data types.
- As a result of the above, higher order functions (map/flatMap) are available and provide power and succintness
- As I understand, Jackson parses via the typical try/catch paradigm. Dealing with JSON errors at compile-time(Play) v. run-time(Jackson) is a no brainer
Bottom line – Play’s JSON library uses a functional programming approach that results in code that is easier to reason about than the Jackson library.
Overall, the choice seems clear to me. Am I missing any pros/cons for either library?
2
It’s important to note, first of all, that the Play ScalaJSON library uses Jackson. In effect, it is a wrapper around the parsing/formatting engine provided by Jackson, so it’s a really good alternative. It provides a nice API around a very fast engine.
Now, the library I’d pick today for any JSON work would be Argonaut. Argonaut is a true functional library from the ground up, and I like many of its decisions.
I don’t really see any point in picking Jackson itself, unless you need the most speed you can get.
3