-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Jackson Release 2.8
Version 2.8 development is planned to start in early 2016.
First official version of https://github.com/FasterXML/jackson-dataformat-properties!
- Support: following modules may become "unsupported" if no maintainers are found:
- Hibernate
- JSON Schema
(note: a new owner was found for Scala module so it is not at risk)
All language features of Java 7 will become available for components other than jackson-annotations and jackson-core (streaming).
Some of Java 2.8 features (most likely parameter names, and possibly Optional types) may be supported directly by jackson-databind instead of modules. Java 8 date/time types will almost certainly remain a plug-in option due to size.
Version 2.7 version had ambitious goals, but many of features originally planned had to be postponed to ensure that the main features started could be completed in time. Here's a list of features that are planned to be tackled for 2.8, in loose order of precedence.
Following features from the initial planning list have been implemented (possibly partially):
Currently there are two ways to indicate an "ignorable type", one that as a property value type indicates that property should be ignored by default without further processing. This is typically needed to avoid serializing "hidden" properties that frameworks add. Methods that exist are:
- Use
@JsonIgnoreTypeon class itself (doable only if you can modify value classes) - Override method
AnnotationIntrospector.isIgnorableType(...)to indicate ignorable status
There are a few issues filed for this from different modules:
- Main issue for
jackson-databind: https://github.com/FasterXML/jackson-databind/issues/861 - Ability to suppress specific Hibernate-induced helper type: https://github.com/FasterXML/jackson-datatype-hibernate/issues/72
- NOTE: relatively easy to just add via
AnnotationIntrospector
- NOTE: relatively easy to just add via
- For JAX-RS, there is tangentially related issue [https://github.com/FasterXML/jackson-jaxrs-providers/issues/56], but it is not exactly same.
Chosen implementation mechanism is the new "type config overrides" mechanism, invoked as follows:
ObjectMapper mapper = ...;
mapper.configOverride(Wrapped.class).setIsIgnoredType(true);which allows calling code to indicate that a given type is to be "ignored type".
Turns out the same mechanism - above-mentioned "type config overrides" -- may be used to also implement these two feature wishes. For example, to make all String arrays unwrap as a simple String on serialization, you could use:
mapper.configOverride(String[].class).setFormat(JsonFormat.Value.empty()
.withFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED));This first version supports a subset of Class annotations, and does not yet have anything for per-property annotations. It should, however, be relatively straight-forward to extend similar approach to overrides of actual property.
Currently all property values are newly created "virgin" Objects. But sometimes it would be useful to see if property already had a default value (set by parent POJO in constructor, typically), and if so, modify that value.
While it is possible to use @JsonInclude on properties, all choices use pre-defined rules; or, in case of NON_EMPTY (and by extension, NON_ABSENT) require matching JsonSerializer.isEmpty(...) to be implemented.
But it should be possible to have a simpler external exclusion handling. This could work by adding support for something like:
public class POJO {
@JsonInclude(value=Include.MATCHING, matcher=MyMatcher.class)
public Value value;where an instance of MyMatcher will be created, and for each property value, MyMatchr.equals() is called to see if value matches: if it does (return true), value will be included; if not (false), it will be excluded.
Such an approach has the main benefit that since Object.equals() is defined for all types, no new types (interface, class) are needed. We can also easily use something like Void.class as the default value.
There are drawbacks as well:
- No context object can be passed so determination must be context-free (note: annotation types also can not refer to
DatabindContext, so context, if any, would need to be untyped as well) - Use of
equals()is an abuse of semantics of the method.
Another approach would be to just create a new interface to fix the issues. Perhaps that makes more sense.
One of the things that has turned out problematic is resolution of Object References via Object Ids. There are a few improvements that could be considered:
- Allow pre-defining set of Object Id to instance mappings
- Allow custom resolution of Object Id references to instances
Although the hope was to add support for "annotation-less" constructors in 2.6, via implied naming, it turned out that there was one remaining big stumbling block: too-late discovery of "creator-capable" constructors.
Basically while it is possible to detect constructors that may act as Creators, due to all parameters having implicit names, this detection happens too late in processing: currently candidate properties (getters, setters, fields, constructor parameters) are collected first, and during this phase, only explicitly annotation constructors are considered. At a later point, all constructors are scanned again, and they are matched to properties that are backed by constructor. But "implied" creators found at this point can not be matched to properties, since they were not constructed during initial pass.
So discovery needs to be rewritten to either make implied-creator detection happen earlier altogether, or to speculative add properties from constructors first, and then decide which constructor, if any, is the primary; properties attached to other constructors will then be trimmed. Either way could potentially work; neither is trivially easy to implement.
Protobuf support added in 2.6 was planned to allow 3 methods for defining protoc schema:
- Read from an external representation (File, String)
- Generate from POJO
- Create programmatically
but due to schedule, only (1) is supported. We should add missing modes.
-
#83: Add
@JsonEnumDefaultValuefor indicating default enum choice if no real match found
-
#117: Add
JsonParser.Feature.ALLOW_MISSING_VALUESto support for missing values -
#253: Add
JsonGenerator. writeEmbeddedObject()to allow writes of opaque native types -
#254: Add
JsonParser.finishToken()to force full, non-lazy reading of current token
-
#990: Allow failing on
nullvalues for creator (addDeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES) -
#1084: Change
TypeDeserializerBaseto takeJavaTypefordefaultImpl, notClass -
#1126: Allow deserialization of unknown Enums using a predefined value (annotated with
@JsonEnumDefaultValue) -
#1136: Implement
TokenBuffer.writeEmbeddedObject(Object)