美文网首页
fasterxml中string字符串转对象json格式单引号错

fasterxml中string字符串转对象json格式单引号错

作者: 脑仁不见啦 | 来源:发表于2019-01-03 10:41 被阅读0次

踩坑1

  • 在处理fasterxml中string字符串转对象json格式,标准的json都是双引号 (" ")

由于数据是单引号(' ')格式。导致了如下报错,特此记录下

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('s' (code 115)): was expecting double-quote to start field name

com.fasterxml.jackson.databind.ObjectMapper 
mapper = new ObjectMapper();

//增加这行配置
//允许使用单引号,默认是false 
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);

mapper.readValue(payload, bean.class);

除了ALLOW_UNQUOTED_FIELD_NAMES,ALLOW_SINGLE_QUOTES还有其它的设置,有用到试试。

相关文章

网友评论

      本文标题:fasterxml中string字符串转对象json格式单引号错

      本文链接:https://www.haomeiwen.com/subject/oltfrqtx.html