Firstly I would point out the your input the "visible" is just a String. So server cannot correctly parse it into the enum Display.
if you need a deserializer, I suggest to have a view of this link below:
JsonMappingException: Can not deserialize instance of enum out of START_OBJECT token
If you choose to annotate this interface using getMapping. It cannot receive a requestBody to parse a complicated json input. Under current situation, you need to add a converter to parse the string into enum which precisely is the solution from @pleft to this problem.
I could provide another converter to this if you need:
final class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
StringToEnumConverterFactory() {
}
public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
return new StringToEnumConverterFactory.StringToEnum(ConversionUtils.getEnumType(targetType));
}
private class StringToEnum<T extends Enum> implements Converter<String, T> {
private final Class<T> enumType;
public StringToEnum(Class<T> enumType) {
this.enumType = enumType;
}
public T convert(String source) {
return source.isEmpty() ? null : Enum.valueOf(this.enumType, source.trim());
}
}
}
Finally I would not suggest to use the jsonProperty to produce the result.
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@AllArgsConstructor
public enum Display {
/**
* test
*/
HIDDEN("hiddenTest"),
/**
* test
*/
VISIBLE("visibleTest"),
/**
* test
*/
SOON("soon");
public final String value;
}
add @JsonFormat(shape = JsonFormat.Shape.OBJECT) annotations to this enum could produce better json result from the server if you are using jackson as the string to json parser.