(to rename and remove properties)

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, aliasing, reordering (for output). …


(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.

Nested Lists in POJOs should work reliably (esp. unwrapped)

Before 2.12 content models with Collection/List valued properties worked well enough for single-level cases, but various combinations of unwrapped (see @JacksonXmlElementWrapper) Lists, nested deeper tended to have edge cases for deserialization (serialization did not have issues); especially in presence of attributes and polymorphic value handling. …


Support ‘java.lang.Record’

(part 5 of “Deeper Dive on Jackson 2.12” mini-series — see “Jackson 2.12 Features” for context)

And now the last “Most Wanted” feature: something requested quite recently (less than year ago) — databind#2709: support brand new java.lang.Record type, introduced in Java 14. Its implementation is a good example of collaboration (see 2.12 Acknowledgments), and the feature has generated a lot of excitement even before getting released.

Basic idea is pretty simple: Record values should behave very much like a POJO with @JsonCreator works. So, these two cases:

public class AsPojo {
private final int x, y;
@JsonCreator
public AsPojo(@JsonProperty("x") int x, @JsonProperty("y") int y)
{
this.x = x;
this.y …


CoercionConfig system

(part 4 of “Deeper Dive on Jackson 2.12” mini-series — see “Jackson 2.12 Features” for context)

After going over couple of rather old feature requests, this one — jackson-databind#2113 — is slightly more recent, addressing requests users have made over past couple of minor versions: Jackson being sometimes too lenient in accepting secondary representations of values.

Background: need for type coercions

With default Jackson settings, you might have value type like:

public class State {
public boolean enabled;
}

and expect to read it from JSON content like:

{ "enabled" : true 

but you could also have content like:

{ "enabled" : 42 }{ "enabled" : "true"…

Annotation-less @JsonCreator (even 1-argument)

(part 3 of “Deeper Dive on Jackson 2.12” mini-series — see “Jackson 2.12 Features” for context)

Another long-requested feature — jackson-databind#1498 — was finally included in 2.12 as well, by introducing a new configuration setting called CosntructorDetector along with couple of default implementations to use.

TL;DNR

The likeliest usage of this feature is something like:

ObjectMapper mapper = JsonMapper.builder()
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
.build()

but what exactly this does will require bit longer explanation.

Background: what is the problem

To understand the feature itself, let’s start with the problem being solved.
Consider this explicitly annotated POJO:

public class Point {
private int x, y;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public Point(@JsonProperty("x") int x, @JsonProperty("y") int x) {
this.x = x;
this.y = y;
}
public int getX() { return x; }
public int getY() { return y; }…


@JsonIncludeProperties

(part 2 of “Deeper Dive on Jackson 2.12” mini-series — see “Jackson 2.12 Features” for context)

Another rather old Jackson Feature Request — jackson-databind#1296 from summer of 2016 — was also included in Jackson 2.12.0 release.
This feature request was asking for something similar to existing @JsonIgnoreProperties annotation which works like so:

@JsonIgnoreProperties({ "password" })
public class Stuff {
public int id;
public String name;
public String password;
}
// serialized as:
{ "id" : 124, "name" : "thingy" }

in this case serialization of value of property password would be prevented and only id and name properties would be included. …


Deduction-Based Polymorphism

(part 1 of “Deeper Dive on Jackson 2.12” mini-series — see “Jackson 2.12 Features” for context)

The oldest open feature request jackson-databind#43 — filed in 2012 — was to support polymorphic types that do not have dedicated “Type Id” but where expected type can instead be deduced based on simple existence/absence of properties.

This is in contrast to existing “classic”, type id-based approach, where type definitions look something like:

@JsonTypeInfo(use=Id.NAME, include=As.PROPERTY, property="@type")
@JsonSubTypes({ ... })
abstract class Animal {
public String name;
}
@JsonTypeName("dog")
public class Dog extends Animal {
public DogFunction function; // BIRD_DOG, GUARD_DOG
}
@JsonTypeName("cat")
public class Cat extends Animal {
public boolean likesMilk;
public boolean hairLength…


(5 Most Wanted features, XML module, Blackbird)

Jackson 2.12.0 was just released on November 29, 2020. It is another “minor” version — meaning that it should be fully backwards-compatible with previous 2.x versions — but packs in much more new functionality than 2.11 event though its development process took exactly as long: 7 months. So it is yet another big leap forward for Jackson 2.x series.

For full details of everything that is included in 2.12.0, please refer to 2.12 Release Notes page: this blog post is meant to give just a brief overview of some of most notably inclusions — after all, there are no fewer than 100 issues resolved (again, twice as many as 2.11!). …


Jackson is a mature and feature-rich open source project that we use, support, and contribute to here at Indeed. In my previous post, I introduced Jackson’s core competency as a JSON library for Java. I went on to describe the additional data formats, data types, and JVM languages Jackson supports. In this post, I will present challenges resulting from Jackson’s expansion, in my view, as Jackson’s creator and primary maintainer. I’ll also share our plans to address these challenges as a community.

A running river surrounded by lush tress in Cape Flattery in Washington
A running river surrounded by lush tress in Cape Flattery in Washington
“The other side of Cape Flattery” by Tatu Saloranta

Growing pains

Over its 13 years, the Jackson project added a lot of new functionality with the help of a large community of contributors. Users report issues and developers contribute fixes, new features, and even new modules. For example, the Java 8 date/time datatype module — which supports Java 8 date/time types, java.time.*, specified in JSR-310 — was developed concurrently with the specification itself by a member of the community. …


Jackson is a mature and feature-rich open source project that we use, support, and contribute to here at Indeed. As Jackson’s creator and primary maintainer, I want to highlight Jackson’s core competencies, extensions, and challenges in this two-part series.

An ocean view over a cliff surrounded by trees in Cape Flattery, Washington
An ocean view over a cliff surrounded by trees in Cape Flattery, Washington
Photo of Cape Flattery by Tatu Saloranta

Jackson’s core competency

If you’re creating a web service in Java that reads or returns JSON, you need a library to convert Java objects into JSON and vice versa. Since this functionality is not available in the Java standard library (JDK), you can use the Jackson library for its core competency: writing Java objects as JSON and reading JSON as Java objects. …

About

@cowtowncoder

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store