Skip to content

@JsonValue ignored for enums #1617

Closed
@thomas-bee

Description

@thomas-bee

According to the docs of Couchbase's @JsonValue: NOTE: when use for Java enums, one additional feature is that value returned by annotated method is also considered to be the value to deserialize from, not just JSON String to serialize as. This is possible since set of Enum values is constant and it is possible to define mapping, but can not be done in general for POJO types; as such, this is not used for POJO deserialization.

The following enum should be deserialised / serialised using its code property. However, @JsonValue has no effect and Springdata Couch tries to deserialise by enum name. Note however that using the original Jackson annotation @JsonValue, the deserialisation does work !
In both cases, serialisation does not work,

public enum ETurbulenceCategory {
    T10("10%"),
    T20("20%"),
    T30("30%");

    private final String code;

    ETurbulenceCategory(String code) {
        this.code = code;
    }
//  DOES WORK FOR DE-SERIALISATION, BUT NOT FOR SERIALSATION
    @com.fasterxml.jackson.annotation.JsonValue
//  DOES NOT WORK AT ALL
//  @com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonValue
    String getCode() {
        return code;
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions