is it possible to deserialize enums, which have a one based index?
enum Status {
Active,
Inactive
}
{status:1} means Status.Active, but Jackson makes it Status.Inactive :(
is it possible to deserialize enums, which have a one based index?
enum Status {
Active,
Inactive
}
{status:1} means Status.Active, but Jackson makes it Status.Inactive :(
Enums have numeric ordinals, starting in zero, and get assigned to each value in an enumeration in the order in which they were declared. For example, in your code
Active
has ordinal0
andInactive
has ordinal1
. You can go back and forth between the value of an enum and its ordinal, like this:Clearly the ordinal
1
corresponds toInactive
(it's not a Jackson problem), as explained above, ordinals in an enumeration are zero-based. Maybe you should fix your code to reflect that, and make sure that{status:0}
meansStatus.Active
.You can create a custom type deserialiser for your enum:
You can then tell Jackson to use your custom deserialiser for a property:
You can also configure the Jackson object mapper to use your custom deserialiser for all occurrences of the target type. See http://wiki.fasterxml.com/JacksonHowToCustomDeserializers.