-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Mix-ins do not work for Enum
s
#2787
Comments
Ok I can reproduce this. Also checked same failure occurs on 2.10 at least. |
So, as per commit message, added failing test; and fixed NPE part. However, functionality will not work as expected, most likely because of the way JDK implements I hope to resolve the second problem too, hence leaving this issue open. And the problem itself is that when buffering content that can not yet be used (both for polymorphic subtype handling and for dealing with unwrapped content), it is not known that type will be needed as But I do not know a good way yet; and changes likely need to go in a new minor version anyway (2.12.0 at earliest). |
Ah. The problem is that unlike POJO properties that are discovered using This should be fixed but will be bit bigger undertaking as it requires changes to |
Enum
s
It would be great to get this fixed but right now there is no good plan to do that, unfortunately. But if anyone wants to tackle it, I'd be happy to help get PR ready. /cc @JooHyukKim this would be another Enum-related challenge. :) |
@cowtowncoder thankssss for the mention! Like you thought, I did try tackling already 🤣. That time I got caught up with other PR, but now that you mention it, I will go back to it now. Do you think below method would be the right place to start? jackson-databind/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java Line 1664 in 95f29d2
And possibly somewhere in that method, do introspection like... Class<?> mixInClass = ctxt.getConfig().findMixInClassFor(type.getRawClass());
JavaType mixInType = ctxt.constructType(mixInClass); then pass in additional lookup for the construction of an EnumDeserializer? |
@JooHyukKim Ideally it would all work through standard mix-in handling and not enum-specific handling. But then again, that may be difficult in its own way. I think a starting challenge is figuring out what Enum values look like, to find how mix-ins apply. |
I realized I have a need to sometimes de-snake-case and rename in addition to lowercase my enum values, so it's really exciting to see the pending PR for this. Mix-ins should prove a lot nicer than writing custom serializers and deserializers. 🎉 |
@ianbrandt Thank you for the support! 🙏🏼 Though probably we might have to write code over again, you could say it's in progress. |
If we could figure out how to match Enum class structure for annotation flattening, that'd be great. I forget exact way Enum values map to "regular" class constructs but it was somewhat non-intuitive (i.e. they had to sort of hack it back in Java .... 1.4? or whenever they were added) |
I will go check. 🙆🏽♂️🙆🏽♂️ As far as I know,
|
@JooHyukKim correct, that's the idea. Change existing machinery to support mix-ins for Enums in general way (both for Enum class and enum values). Main concerns/questions are just that:
|
I think someone else is tagged 😅here. |
Sorry. Auto-completion for the win. :-/ |
I just realized there might be a feature that might satisfy your needs, @ianbrandt ! 👍🏻 There is a recent PR #3792 that features naming strategy for @EnumNaming(EnumNamingStrategies.CamelCaseStrategy.class)
static enum EnumFlavorA {
PEANUT_BUTTER, // handled as peanutButter
SALTED_CARAMEL, // as saltedCaramel
@JsonEnumDefaultValue
VANILLA; //
} |
Enum
sEnum
s
It seems this issue can be closed now, addressed by #3990 ? |
Yes, included as fixed in 2.16.0-rc1 release notes, just forgot to close issue itself. |
register mixin via
.addMixIn(SomeEnum.class, SomeEnumMixin.class)
try to deserialize sometithing
ObjectMapper throws NullPointerException
I've tested on 2.11.0 and 2.11.1
The text was updated successfully, but these errors were encountered: