Although Jackson started simply as a JSON parser library (see “Brief history of Jackson”), over the years it has grown to support dozen other data formats using extensions called (dataformat) Modules. At high level the API used is identical to that of reading and writing JSON — jackson-databind package and its API is format-agnostic — although there are typically some configuration settings that vary. So in theory it should be very easy to start using Jackson with one of supported (*) formats.
Jackson core components like databind do not use Guava for anything: not because it was not a very useful library (it is!), but to keep Jackson core components dependency-free (*).
But there is an extension module available to let Jackson users use databind to read and write many Guava values: jackson-datatype-guava extension modules.
It is registered like so:
ObjectMapper mapper = JsonMapper.builder()
.build(); // Jackson 2.10+
// or with earlier Jackson versions:
ObjectMapper mapper = new ObjectMapper();
and after doing this you can read and write many of standard Guava datatypes.
ImmutableList<Integer> list =…
First, a disclaimer: I do not know if this is a good idea or not — and I definitely do not promote its application, if any, at this point. :)
A user presented me with a use case for Jackson JSON parsing, wherein query parameters can contain String and Number values, like so:
and wanted to just parse them into
JsonNode nameNode = mapper.readTree(request.getParam("name"));
This does not — and should not — work as String
Bob is not valid JSON (all JSON String values MUST be quoted).
JSON specification defines “JSON Values” as just “[JSON] Objects and Arrays” (*), and most JSON usage examples focus on that: for example, how to read an HTTP Request where payload is a JSON Object, how to write matching HTTP Response where payload is similarly a JSON Object.
There are countless articles covering such usage: with Jackson you would usually use something like this:
final JsonMapper mapper = new JsonMapper();
MyRequest reqOb = mapper.readValue(httpRequest.getInputStream(), MyRequest.class);
// or: JsonNode reqAsTree = mapper.readTree(...)
// ... processing, and then
MyResponse respOb = new MyResponse(.....);
or maybe the actual usage would be by…
(or, as Monty Python gang used to say, “And Now for Something Completely Different” — a minor break from my usual CS/Java writing)
Over time, a few colleagues and friends in US have asked me about Finnish cuisine: what is it like, what are the good dishes etc. I have tended to answer along the lines of the (in)famous Churchill’s quote on Royal Navy (“rum and sodomy”), suggesting that Finnish food tradition consists mostly of variations meat and potatoes with a strong undercurrent of underseasoning.
While there is some truth to that quip, I have grown to realize over time…
As most Java developers know, Jackson is a very powerful library for converting between Plain Old Java Objects (POJOs) and various data formats, most notably JSON. By defining Java object — and especially with optional annotations — you can construct elaborate data structures to match almost any use case.
There is quite a bit of documentation showing how to do that; for example:
But while useful and often convenient, you do not really HAVE TO define Java classes write or read JSON with Jackson: for “casual” usage there are…
First the disclaimer: as I write this (end of Jan 2021), Jackson 3.0 is still very much Work-in-Progress (see earlier Jackson 3.0 vision): even the first release candidate is months away. My hope is to release the final 3.0 some time during 2021. Until then you can see the progress on
master branches of Jackson repos and build locally, kick the tires, but should not use it for any real work.
With that out of the way, let’s look at the first major new feature that has been implemented for 3.0 (also listed on Jackson 3.0 …
The Jackson project is by now almost 14 years old: the first public version was released in the summer of 2007. A lot has happened over the years: a two dozen “minor” releases (ones with new features) from 1.0 through to 2.12 and more than 100 patch releases (ones with only bug fixes) have been released over the years.
But in addition there has been one transition known as the “major version upgrade”, in which the new version is not backwards-compatible with the older version. This occurred with the release of Jackson 2.0.0 …
Something that I briefly covered earlier (in Jackson 2.11 features) is the new jackson-jr extension called
jackson-jr-annotation-support. But as I have not gotten much feedback since that release, maybe it is time to re-review this additional functionality.
(note: if you are not familiar with Jackson-jr library itself, you may want to read “Jackson-jr for ‘casual JSON’” first before continuing)
Introduction of general “extension” mechanism for jackson-jr — not unlike full Jackson’s “modules” — coincided with the addition of first such extension, “jackson-jr-annotation-support”, which offers optional support for some of basic Jackson annotations for basic detection (and exclusion) of properties; renaming…
(continuation of “Deeper Dive on Jackson 2.12” mini-series — see “Jackson 2.12 Features” for context)
Aside from “big 5” features discussed so far, another major area of work this time around was that of Jackson XML dataformat module: no fewer than 26 XML-specific issues were resolved for this release.
As usual, you can see the full list of changes on 2.12 Release Notes; here we’ll dig deeper into most notable fixes and improvements.
Before 2.12 content models with
List valued properties worked well enough for single-level cases, but various combinations of unwrapped (see
Lists, nested deeper tended to have…
Open Source developer, most known for Jackson data processor (nee “JSON library”), author of many, many other OSS libraries for Java, from ClassMate to Woodstox