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

Allow injection of 'transient' fields #77

Closed
cowtowncoder opened this issue Sep 24, 2012 · 2 comments
Closed

Allow injection of 'transient' fields #77

cowtowncoder opened this issue Sep 24, 2012 · 2 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

(note: moved from http://jira.codehaus.org/browse/JACKSON-817)

Due to the way Jackson property introspection works, transient fields are ignored and one can not use @JacksonInject for them.
However, it would be nice to be able to do that, since while such fields should not be serialized, it would make sense to be able to inject values for them during deserialization. This may require some changes to property discovery.

@licarth
Copy link

licarth commented Feb 10, 2015

I guess a workaround for this is to create a @JsonCreator annotated constructor and pass as parameter the field that needs to be injected.

instead of :

public class Entity{
   @JacksonInject
   private transient Object toBeInjected;
}

(@JacksonInject will be ignored in code above)
rather do :

public class Entity{
    private transient Object toBeInjected;

    @JsonCreator
    public Entity(@JacksonInject Object toBeInjected){
        this.toBeInjected = toBeInjected;
    }
}

The field itself can remain transient, and will be injected thanks to the @JsonCreator constructor.

@cowtowncoder cowtowncoder added this to the 2.6.0 milestone May 15, 2015
@cowtowncoder
Copy link
Member Author

Looks like work for #296 allows fixing this, finally.

christophercurrie pushed a commit to christophercurrie/jackson-databind that referenced this issue Jul 19, 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