[英]On Kotlin jackson ObjectMapper.readValue() causes java.lang.IllegalStateException: readValue(content, jacksonTypeRef<T>()) must not be null
On crashlytics I am getting an java.lang.IllegalStateException: readValue(content, jacksonTypeRef<T>()) must not be null
exception on the 4th line. 在crashlytics上,我收到
java.lang.IllegalStateException: readValue(content, jacksonTypeRef<T>()) must not be null
在第四行java.lang.IllegalStateException: readValue(content, jacksonTypeRef<T>()) must not be null
异常。 I couldn't reproduce it. 我无法复制它。 I think
mapper.readValue(string)
is returning null where is shouldn't. 我认为
mapper.readValue(string)
在不应该返回null的地方。 I handled the string being null case so other than string being null what could cause mapper.readValue(string)
to return null so I end up with this exception and what is possible way to reproduce this error? 我处理了字符串为null的情况,所以除了string为null之外,这可能导致
mapper.readValue(string)
返回null,所以我最终mapper.readValue(string)
此异常,并且有什么可能的方法来重现此错误?
var token: token? = null
get() {
val string = sharedPreferences.getString(TOKEN_KEY, null)
field = if (string == null) null else mapper.readValue(string)
return field
}
set(value) {
field = value
val json = mapper.writeValueAsString(value)
sharedPreferences.edit().putString(TOKEN_KEY, json).apply()
}
事实证明sharedPreferences.getString(TOKEN_KEY, null)
在这种情况下, sharedPreferences.getString(TOKEN_KEY, null)
返回“ null”字符串,而mapper.readValue(string)
返回null
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.