Deserialisieren eines Enums mit Jackson

Ich versuche und dann nicht zu Deserialisieren eines enum, die mit Jackson 2.5.4, und ich verstehe nicht ganz, siehe mein Fall draußen. Mein input-strings sind Kamel-Fall, und ich möchte einfach Karte auf standard-Enum-Konventionen.

@JsonFormat(shape = JsonFormat.Shape.STRING)
public enum Status {
    READY("ready"),
    NOT_READY("notReady"),
    NOT_READY_AT_ALL("notReadyAtAll");

    private static Map<String, Status> FORMAT_MAP = Stream
            .of(Status.values())
            .collect(toMap(s -> s.formatted, Function.<Status>identity()));

    private final String formatted;

    Status(String formatted) {
        this.formatted = formatted;
    }

    @JsonCreator
    public Status fromString(String string) {
        Status status = FORMAT_MAP.get(string);
        if (status == null) {
            throw new IllegalArgumentException(string + " has no corresponding value");
        }
        return status;
    }
}

Ich habe auch versucht @JsonValue auf eine getter-ohne Erfolg, war die eine option sah ich berichtete an anderer Stelle. Sie alle sprengen mit:

com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of ...Status from String value 'ready': value not one of declared Enum instance names: ...

Was mache ich falsch?

InformationsquelleAutor der Frage jwilner | 2015-07-29

Schreibe einen Kommentar