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

2019-01-03  本文已影响0人  脑仁不见啦

踩坑1

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

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还有其它的设置,有用到试试。

上一篇下一篇

猜你喜欢

热点阅读