【发布时间】:2022-09-27 16:31:35
【问题描述】:
我一直在尝试解决在为我的枚举值解析空字符串时发生的错误。我尝试了以下解决方案
getJacksonObjectMapper(template).coercionConfigFor(LogicalType.Enum).setCoercion(CoercionInputShape.EmptyString,CoercionAction.AsNull)
和
getJacksonObjectMapper(template).deserializationConfig.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
getJacksonObjectMapper(template).enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
有人可以帮我解决这个问题吗?错误跟踪如下所示
JSON parse error: Cannot coerce empty String (\\\"\\\") to `Gender` value (but could if coercion was enabled using `CoercionConfig`); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot coerce empty String (\\\"\\\") to `Gender` value (but could if coercion was enabled using `CoercionConfig`)\\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream);
我的枚举是
enum Gender{
M, F;
}