-
Notifications
You must be signed in to change notification settings - Fork 6
JSTEP 7
(Back to JSTEP page)
Related change issues: JSTEP-3 contains/-ed aspects of JsonNodeFeature
Tatu Saloranta (@cowtowncoder)
- 2022-01-16: The first draft version
Over time, various XxxFeature
on/off options have proven useful and popular with developers: they are easy to set, change and (for the most part), understand.
Original set of "Features" were configurable at Streaming API and Databind level, including:
-
JsonParser.Feature
/JsonGenerator.Feature
/JsonFactory.Feature
for Streaming API -
MapperFeature
/SerializationFeature
/DeserializationFeature
for databind
and for Streaming API, further split of format-specific (often JSON-specific) vs. generic (across all or most formats) features, resulted in:
-
JsonParser.Feature
split into genericStreamReadFeature
andXxxReadFeature
(likeJsonReadFeature
) -
JsonGenerator.Feature
split into genericStreamWriteFeature
andXxxWriteFeature
(likeJsonWriteFeature
).
But while this split allowed better support for Format-specific features (via Streaming API), there is no similar mechanism for more granular configuration for datatype-specific features. This has lead to inclusion of some "too [datatype] specific" features at databind level; for example:
DeserializationFeature.READ_ENUMS_USING_TO_STRING
DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
Such configuration is against the idea that these Features should be cross-cutting across dataformats AND datatypes. But it is worth noting that there is need for such configuration, at some other granularity. This lead to the idea of "datatype-specific" features, to cover up to 3 initial datatypes:
-
JsonNode
(Tree Model) configuration -- since it differs a lot from POJO configuration, and is difficult to configure -
Enum
configuration -- a few entries already leaked into generic features, and a few configuration aspects missing -
Date/Time
configuration -- similar to Enums, some configurability exists in general features, as well as via@JsonFormat
, but there's need for more.
There are a few things to consider with respect to the general idea. For example:
- Would a single
DataTypeFeature
enum suffice? Based on having multiple general "datatypes", settings, not really.- So, need multiple concrete Feature
Enum
s - But would like to avoid need to add all relevant plumbing -- would prefer general-purpose extension mechanism
- So, need multiple concrete Feature
- How similar should configuration interface (API) be compared to, say,
DeserializationFeature
?- Seems like usage should be very similar, perhaps almost identical
- Possible to implement if we make
DataTypeFeature
an interface that actual Feature enum implements
- Do these features need to be per-call, or per-mapper?
- Since some of the settings should be per-call, it seems necessary to make them ALL per-call
- Needs to be considered when adding new feature entries: should adding Features that do not work on per-call scope
- Should we support pluggable, per-datatype-module way of adding
DataTypeFeature
s?- Ideally that would be great, but coordination of new types seems difficult (depending on mechanism)
- Would likely lead to worse issues wrt. cross-version (different minor version between Datatype and Core modules)
- At least initially the plan is NOT to support anything other than
DataTypeFeature
s defined by Databind module itself
So, to summarize:
- We would have
DataTypeFeature
general interface for each actual feature (say,JsonNodeFeature
) to implement: this interface mostly exists to keep Databind API simple and does not affect users directly (no functionality to access through it) - There will be multiple Enum subtypes of
DataTypeFeature
, and more can (and likely will) be added over future Jackson versions - Datatype Modules cannot define additional subtypes: these features will relate to either somewhat abstract/general types (Date/Time), or JDK- (Enum) and Jackson-specific (
JsonNode
) types