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

Add support for java.beans.Transient #857

Closed
tmortagne opened this issue Jul 6, 2015 · 7 comments
Closed

Add support for java.beans.Transient #857

tmortagne opened this issue Jul 6, 2015 · 7 comments
Milestone

Comments

@tmortagne
Copy link

java.beans.Transient is a new Java bean annotation introduced in Java 7 which has pretty much the same meaning as transient keyword except that you can put it on methods to ignore some getters for example.

I guess the issue is that Jackson follow Java bean but does not actually use java.beans.Introspector and impossible to support this annotation before Jackson move to Java 7 (which is not the case from what I understood from http://wiki.fasterxml.com/JacksonDownload).

Any idea what would be the cleanest to support that in the meantime ? I tough about setting a custom visibility checker but maybe there is a better way.

@cowtowncoder
Copy link
Member

First of all, thank you for reporting this. I was not aware of this addition.

The technical answer is that sub-classing JacksonAnnotationIntrospector, overriding hasIgnoralMarker() method (or whatever the name was, something like that) to check for annotation, return Boolean.TRUE.

Check can not be added in jackson-databind yet, as it only requires Java 6 for current versions (at least until 2.6). When baseline is increased (we will probably discuss that for Jackson 2.7), check could be directly added.
Until then, jackson-datatype-jdk7 project would be the natural place for this feature; it does not yet define custom annnotation introspector, but it could. And then it would be matter of documentation to let users know to register alternate introspector; or make it auto-register.

@tmortagne
Copy link
Author

Actually I did not knew about jackson-datatype-jdk7, glad I ear about it before reporting features it adds :)

@cowtowncoder
Copy link
Member

No problem, right now it's quite minimal. But there is also jackson-datatype-jdk8, as well as jackson-datatype-jsr310 (Java 8 date time), so seemed appropriate to have sort of convention of adding features for new JDKs.

@cowtowncoder cowtowncoder changed the title Jackson dos not take into account java.beans.Transient (2.7) Jackson dos not take into account java.beans.Transient (requires JDK 7) Sep 24, 2015
@cowtowncoder
Copy link
Member

Discussions on-going to make Jackson 2.7 require Java 7 / JDK 1.7. If so, could be added in core jackson-databind, which would be good.

@tmortagne tmortagne changed the title (2.7) Jackson dos not take into account java.beans.Transient (requires JDK 7) (2.7) Jackson does not take into account java.beans.Transient (requires JDK 7) Sep 25, 2015
@cowtowncoder
Copy link
Member

Ok: Jackson 2.7 will require Java 7, so we can actually use this marker annotation.

One potential concern I have is that although it would be possible to simply consider this an alias of @JsonIgnore, this is not quite what keyword transient does, because by default it only prevents use of the particular field marked, unless MapperFeature.PROPAGATE_TRANSIENT_MARKER is enabled.
So the annotation should probably work the same way. But the problem then is that access to transient is not done via AnnotationIntrospector but rather via direct check. So this may actually require an additional method in AnnotationIntrospector.

On the other hand, reading through the Javadocs, annotation can only be defined for methods, and it looks like intent is to indeed consider this ignoral marker.

So I'll go ahead and implement it that way.

@tmortagne
Copy link
Author

So I'll go ahead and implement it that way.

Note: for what it worth that's what I did on my side for now so at least me will be happy :)

@cowtowncoder
Copy link
Member

Ok good, so at least this will do what some of the users are using it for.
(in fact, everyone whose use cases I am familiar with :) )

@cowtowncoder cowtowncoder changed the title (2.7) Jackson does not take into account java.beans.Transient (requires JDK 7) Add support for java.beans.Transient Nov 8, 2015
@cowtowncoder cowtowncoder added this to the 2.7.0 milestone Nov 8, 2015
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