Skip to content

Add a way to specify "inject-only" with @JacksonInject #1381

Closed

Description

@cowtowncoder

Currently all injectable properties also allow binding of data from input, so if there is a JSON value for property, it will override anything injected. But this may not always be what user wants; sometimes it may be preferable to only use injection (and quietly drop value from data, if any). Or possible even reverse, that is, allowing injection to optional override value, but if no injectable value given to default to value from input data.

To support this change, some other changes are needed:

  1. Create JacksonInject.Value to contain aspects (name, precedence for now, possibly more in future)
  2. Create a new enum type for JacksonInject to indicate if and how input data value is to be used.
  3. Change introspection method in AnnotationIntrospector to produce new value object but allow chaining with old implementations, to support some level of interoperability
  4. Change introspectors (Guice module uses one I think; OSGi too?)

As to enum to use (JacksonInject.Input?), perhaps:

  • Primary: (default) if input data has property, use that, not injected value
  • Secondary: input data only used if no injected value can be found
  • Never: input data never used, only injected value

Another possible improvement could be to add another property (required?) to indicate whether it is acceptable to not have an injectable value defined, when one is needed (which is in all cases except with Primary, and finding actual data).
If no value is found, and injection is NOT required (required would be the default for now) null would be injected.

Activity

  1. cowtowncoder commented on Apr 6, 2018

    @cowtowncoder
    MemberAuthor

    Note: for 2.x light-weight solution via #1565, but need to rewrite for 3.0 to do proper checking, if (and only if) we can keep track of actual declaration location.

  2. Marcono1234 commented on Apr 5, 2021

    @Marcono1234
    Contributor

    Has this been partially solved through FasterXML/jackson-annotations#120?

  3. cowtowncoder commented on Apr 5, 2021

    @cowtowncoder
    MemberAuthor

    Annotation issue can only add new properties but not actual handling (package only contains annotation declarations/definitions).

  4. 12 remaining items

  5. added a commit that references this issue on Jun 20, 2025
  6. added a commit that references this issue on Aug 26, 2025
  7. added 3 commits that reference this issue on Sep 6, 2025
  8. added and removed
    2.20
    on Nov 6, 2025
  9. added 3 commits that reference this issue on Nov 14, 2025
  10. added this to the 2.21.0 milestone on Nov 16, 2025
  11. cowtowncoder commented on Nov 16, 2025

    @cowtowncoder
    MemberAuthor

    Implemented for 2.21(.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.21most-wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions