Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson conflates Java object serialization configuration and its own. #269

Closed
lhunath opened this issue Apr 5, 2016 · 3 comments
Closed

Comments

@lhunath
Copy link

lhunath commented Apr 5, 2016

The Java language has the transient property to indicate that certain fields should not take part in object serialization. This keyword is part of its own internal object serialization framework of which Serializable is the marker that you're subscribing to it.

Jackson appears to conflate Java 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 transient 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 utterly impossible to include transient fields in a Jackson serialization process.

This becomes painfully 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 which SharedPreferences supports well. 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. Now, Jackson ignores them wholesale, even when annotated @JsonProperty, which is counter-intuitive (at a glance, once would expect an 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.

@cowtowncoder
Copy link
Member

@lhunath for larger discussion please use mailing lists. General discussion on usage of transient marker would fall under this category; especially since this is the first time in past 8 years when this has been reported as a significant issue.

I assume what you want is something like "allow serialization of transient fields" or such. If so, issue should go in jackson-databind as jackson-core contains streaming parser and generator which have no role in databinding aspect, including handling of transient fields.
So if you could re-file this over there (I would move it but AFAIK github has no "transfer issue" functionality, alas), that would make sense.

Also: instead of arguing with deeper semantics on your personal views, it makes sense to explain actual expected behavior. I do not take claims of generally accepted consensus at face value -- especially in cases where there exists plenty of prior art to the contrary (many if not most Java serialization frameworks outside of JDK serialization take transient keyword to mean exclusion).
I have nothing against proposed improvements for allowing alternate handling, I just dislike strong statements without much backing facts.

@lhunath
Copy link
Author

lhunath commented Apr 5, 2016

Thanks @cowtowncoder, I wasn't entirely certain. I'll refile and perhaps edit a bit.

@lhunath lhunath closed this as completed Apr 5, 2016
@lhunath
Copy link
Author

lhunath commented Apr 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants