0%

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

在处理fasterxml中string字符串转对象json格式,标准的json都是双引号 (” “);由于数据是单引号(‘ ‘)格式。导致了如下报错,特此记录

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

1
2
3
4
5
6
7
8
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还有其它的设置,有用到试试。

欢迎关注我的其它发布渠道