Jackson 2.14 sneak peek

Another “minor minor” release

One thing to note is that as with 2.13 — and different from Jackson 2.12– version 2.14 can be considered another “smaller” minor release: most improvements are incremental and there is no wide expansion of functionality (no new format or datatype modules)

  1. Improvements to JSON parser (performance, support for more “non-standard” content reading, alternate non-blocking input source)
  2. Datatype-specific configurability for ObjectMapper (and ObjectReader / ObjectWriter)
  3. More ways to use JsonNode (Tree Model)

Compatibility: Java 8 now baseline for jackson-core, jackson-jr

2.14 should be highly compatible with 2.13 even beyond the usual minor-to-minor compatibility. The only notable compatibility change is that Java 8 will now be the minimum requirement for jackson-core (streaming parser/generator) and jackson-jr modules. Jackson-annotations will remain the one and only module that still only requires Java 6 (until Jackson 3).

Feature: Improved @JsonAnySetter handling

Up until 2.14, @JsonAnySetter has been usable either for

  1. 2-argument setter method (which gets called once per otherwise unmapped property), OR
  2. Map<String, T> valued non-null Field (in which case all otherwise unmapped properties are bound to an existing Map
  • Non-initialized (null) Map wherein Map is dynamically created if (and only if) needed (databind#3559)
  • ObjectNode (JsonNode that represents JSON Object value) value Field (databind#3394)
public class MapAnyBean {
// no need to initialize if one of "well-known" Map types:
public Map<String, Object> values;
}
public class JsonNodeBean {
// May initialize but no need to:
public ObjectNode valuesAsNodes;
}

Feature: ByteBuffer-backed non-blocking JSON parser

As is well-known (or is it? :-) ) in addition to its default blocking I/O based parser, Jackson ALSO provides an efficient, fully-featured, world-class non-blocking (aka “async”) JSON parser implementation (since Jackson 2.9, see “Non-Blocking Reading” section).
But so far it has required content to be fed as raw byte arrays (byte[]).

Feature: Support for more Non-Standard “JSON” constructs

Over time there have been many requests to support decoding of “almost JSON” (or “JSON-like”) content; especially for things like:

  • Optional/extra separators (trailing comma, missing values)
  • Flexible number representations
  • Optional comments
  • JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS (jackson-core#773) to allow floating-point numbers like 124. and -8.
  • JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS (jackson-core#774) to allow numbers with leading plus sign, like +25 and +0.17

Feature: FASTER floating-point number reading and writing

One area where JSON content handling has significant performance disadvantage compared to binary formats is that of floating-point (non-integer) number reading and writing.
Jackson 2.14 will now incorporate alternative, high(er)-performance algorithm (“Schubfac”) for reading and/or writing FP numbers in JSON content.

  1. StreamReadFeature.USE_FAST_DOUBLE_PARSER (jackson-core#577)
  2. StreamWriteFeature.USE_FAST_DOUBLE_WRITER (jackson-core#749)
JsonFactory f = JsonFactory.builder()
.enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER)
.enable(StreamWriteFeature.USE_FAST_DOUBLE_WRITER)
.build();

Feature: datatype-specific configurability (JsonNodeFeature, EnumFeature?)

One “Bigger” feature, explained in JSTEP-7 proposal, is the ability to extend ObjectMapper configurability since existing (pre-2.14) choices are limited to:

  • Generic databinding Features (DeserializationFeature, SerializationFeature, MapperFeature), affecting all content
  • Generic and Format-specific low-level stream read/write features (like JsonReadFeature, CsvWriteFeature etc)
  • Fully format-specific extensions through either format-specific schemas (CsvSchema, JavaPropsSchema) or settings configurable only through format-mapper builder (CsvMapper.builder().setCSVSpecificThings(123) )
  • Some serializers/deserializers may require direct configuration for exact specifics of Java class in question
  • Different kinds of DatatypeFeature implementations (as special kinds of Enums)
  • New entries to said implementations
  • JsonNodeFeature.READ_NULL_PROPERTIES (databind#3421)— whether null values from incoming JSON will result in NullNode entries being added in ObjectNode (enabled) or not (disabled)
  • JsonNodeFeature.WRITE_NULL_PROPERTIES (databind#3476)— whether NullNode valued entries of ObjectNode will be written out as JSON nulls (enabled) or skipped (disabled)
// May configure ObjectMapper default settings:
ObjectMapper mapper = JsonMapper.builder()
.disable(JsonNodeFeature.READ_NULL_PROPERTIES)
.build();
// and/or change for ObjectReaders/-Writers
JsonNode rootNode = mapper.readerFor(JsonNode.class)
.enable(JsonNodeFeature.READ_NULL_PROPERTIES)
.readValue(inputJson);
String json = mapper.writer()
.disable(JsonNodeFeature.WRITE_NULL_PROPERTIES)
.writeValueAsString(rootNode);

Feature: JsonNode.withObject(JsonPointer) / .withArray(JsonPointer)

Use of JsonPointer with JsonNode is quite convenient for read access:

JsonNode doc = mapper.readTree(docSource);
// From {"users: [
// { "name" : "Bob", "age" : 42 }
// ])
int age = doc.at("/users/0/age").asInt();
  1. JsonNode.withObject(JsonPointer) — will traverse specified path and ensure that at its end there will be a JSON Object (ObjectNode), which is returned
  2. JsonNode.withArray(JsonPointer) — will traverse specific path and ensure that at its end there will be a JSON Array (ArrayNode), which is returned
ObjectNode root = mapper.createObjectNode();
root.withObject(JsonPointer.compile("/users/0")).put("age", 42);

Other Modules

As per 2.14 Release Notes there are definitely more noteworthy changes than I have time to write for so if interested, feel free to poke around.

That’s All, Folks!

And there we have it. I hope to get the first (and possibly only) Release Candidate out Very Soon Now — and the official 2.14.0 out by September, 2022.

--

--

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
@cowtowncoder

@cowtowncoder

377 Followers

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