【问题标题】:Error on Parsing the empty string for an Enum : JSON parse error: Cannot coerce empty String (\"\")解析 Enum 的空字符串时出错:JSON 解析错误:无法强制空字符串 (\\\\"\\\\")
【发布时间】: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;
}

    标签: json kotlin jackson


    【解决方案1】:

    .enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)

    【讨论】:

      猜你喜欢
      • 2013-05-10
      • 1970-01-01
      • 2012-10-04
      • 2011-12-16
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      相关资源
      最近更新 更多