-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
The Java language has the transient
property which indicates that certain fields should not take part in its Java object serialization framework of which Serializable
is the hallmark.
Jackson appears to conflate Java's object serialization configuration with its own by forcing all transient
fields to be excluded from any Jackson serialization. While it is a good idea for the transient
keyword to provide a hint to Jackson that the field is uninteresting for its own serialization, the problem is really that this behaviour cannot be turned off. It is therefore impossible to include transient
fields in a Jackson serialization process.
This becomes obvious when the application uses an object for two distinct types of serialization.
Case in point, I want to serialize an object in Android for storage within its SharedPreferences
by serializing it using Java's object serialization (well supported by SharedPreferences
). I also want to serialize this object into JSON for submission to a remote server via HTTP. When I serialize the object into JSON, I need to include a few data points that should not be included in the SharedPreferences
storage, hence my setting these fields as transient (to exclude them from the latter, Java object serialization). Unfortunately, this makes Jackson ignore them wholesale, even when annotated @JsonProperty
(which is counter-intuitive - at a glance, one would expect a Jackson-annotated property to override a non-specific language keyword). There is also no way to change the configuration of the Jackson serialization mechanism to stop ignoring the transient
keyword.
As such, this is a feature request to provide the ability to disable filtering out all transient
fields from Jackson's serialization process.