question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support use of `@JsonAlias` for enum values

See original GitHub issue

Feature request Would like to suggest the following feature. The enabling of @JsonAlias for enums.

Why? Enabling @JsonAlias for enums can help users that are faced with legacy properties.

Assume that version 0.1.0 has:

{
  "key": "stringvalue"
}

and version 0.2.0 has:

{
  "key": "stringValue"
}

Assume both are valid values and we want to map them to one Enum value. Having @JsonAlias available for this purpose can help to avoid bloat-code or custom de-serializers that do this.

Current behaviour Not implemented.

Expected behaviour I’d assume the same behaviour as with class members applies. So using @JsonProperty and @JsonAlias combined would yield the same result except for values not keys.

Example

public enum MyEnum{
    @JsonProperty("stringvalue") //<- Value Jackson should use during serialization and de-serialization.
    @JsonAlias({"stringValue"}) //<- Additional value, valid only during de-serialization.
    STRING_VALUE //<- Would assume "string_value" is ignored and not added to the list of valid values
}

Extra information Version: 2.9 Occurs in patch: Yes Feature request was also mentioned in: this issue (Couldn’t find the accompanying Feature request)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Oct 8, 2019

Excellent! I’ll add this to my work-in-progress list and hopefully have time to review tomorrow.

0reactions
cowtowncodercommented, Nov 24, 2019

Big thanks to @RobertDiebels for contributing this & apologies for merging taking time. Will be nice addition to 2.11.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How to deserialize alternative values for an enum field ...
Now I want to remove the STUDENT_ prefix from the enum value, but without breaking existing callers of the API. I tried to...
Read more >
How To Serialize and Deserialize Enums with Jackson
In this quick tutorial, we'll learn how to control the way Java Enums are serialized and deserialized with Jackson 2.
Read more >
JsonAlias (Jackson-annotations 2.9.0 API) - FasterXML
Annotation that can be used to define one or more alternative names for a property, accepted during deserialization as alternative to the official...
Read more >
Using @JsonFormat to serialize Java Enum As Object - LogicBig
OBJECT to serialize (but not deserialize) enums as JSON Objects (as if they were POJOs). This only works when @JsonFormat is used on...
Read more >
Jackson @JsonProperty and @JsonAlias Example
On this page we will provide Jackson @JsonProperty and @JsonAlias annotation example. ... @JsonProperty can also be used with Enum.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found