Skip to content
This repository has been 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 opened this issue Mar 9, 2016 · 2 comments
Milestone

Comments

@edwag
Copy link

edwag commented Mar 9, 2016

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?).

@cowtowncoder
Copy link
Member

Ah. Good catch, thank you for reporting this. I think it's a side-effect of a few things, obviously unintended.

I would have to look to know what would make sense wrt fix; I suspect part of the problem is that ideally AnnotationIntrospector should have very little handling, but due to backwards-compatibility (between JacksonAnnotationIntrospector, JAXBAnnotationIntrospector) that piece of functionality was added in there. Going forward it should be possible to move it out (esp. for 2.8), just not sure what the short-term solution would be.

@cowtowncoder cowtowncoder added this to the 2 milestone Mar 13, 2016
cowtowncoder added a commit that referenced this issue Mar 13, 2016
@cowtowncoder cowtowncoder modified the milestones: 2, 2.7.3 Mar 13, 2016
@cowtowncoder
Copy link
Member

I think I figured out the way to fix the problem, and changed code in jackson-databind (plus minor related change in JAXB modules); fix will be in 2.7.3.

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

No branches or pull requests

3 participants
@cowtowncoder @edwag and others