I encounter a case where I need to overwrite an Enum’s values but cannot change the code directly.
There is a deprecated package with an entity having an enum in its parameter list:
public class A {
OldEnum member;
public A(OldEnum member) {
this.member = member;
}
}
public enum OldEnum {
// The values of @JsonProperty need to be updated
@JsonProperty("value1")
VALUE_1,
@JsonProperty("value2")
VALUE_2
}
I need to initialize an instance of class A to use this package. However, I find that:
- Simple initialization is not working here, because the Enum value is wrong.
- I cannot directly change the code of the Enum in the package as it was downloaded from Maven.
Now I cannot find a way to update the enum value. Does anyone have any idea for that?
1