Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

@JsonProperty annotations on enums are not respected if parameter names module is registered #32

Closed
@edwag

Description

@edwag

If you annotate an enum value with @JsonProperty("foo"), that value should be serialized/deserialized as "foo". This fails if the parameter names module is registered - I've made a test case at https://github.com/edwag/jackson-parameter-names-test-case to clarify what I mean.

I believe that this is what happens:

  1. The ParameterNamesAnnotationIntrospector is added to the SetupContext using insertAnnotationIntrospector, so it takes precedence over the default JacksonAnnotationIntrospector (i.e. it is the primary AnnotationIntrospector in an AnnotationIntrospectorPair).
  2. Because the ParameterNamesAnnotationIntrospector inherits findEnumValue from AnnotationIntrospector, when it inspects an enum value it just returns value.name()
  3. Because the ParameterNamesAnnotationIntrospector didn't return null, the default JacksonAnnotationIntrospector doesn't get a chance to inspect the enum value (due to the behaviour of AnnotationIntrospectorPair).
  4. We therefore use value.name() instead of the value of the @JsonProperty annotation.

I'd be happy to contribute a fix, but it's not obvious to me what the right way to fix this is (e.g. is this actually an issue with AnnotationIntrospectorPair?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions