添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected characterwas expecting double-q

公众号JavaEdge

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected characterwas expecting double-q


解决fasterxml中string字符串转对象json格式错误问题。

springboot中jackson使用的包是fasterxml的。可以通过如下代码,将一个形如json格式string转为一个java对象:

com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
mapper.readValue(字符串, javabean.class);

但是,当我们要转的字符串是这种格式的就会报错,因为这种格式并不是规范的json格式:

{success:2,message:'认证已通过!设备未添加,请与和航联系。设备编号:1101'}

错误信息是:

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

意思就是:fasterxml期望字段名带有双引号,也就是期望是这样的:

{"success":2,"message":"认证已通过!设备未添加,请与和航联系。设备编号:1101"}

通过对比,发现上面的字符串和规范的json字符串主要有两个不同点


  1. 字段名未用引号
  2. 第二个是使用了单引号

这都是不规范的Json格式写法。

当然,最好的解决方式是将string字符串转成规范的json格式,但是由于某些原因,不得不使用这种格式怎么办呢?

解决:

com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
//允许使用未带引号的字段名
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
//允许使用单引号
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);

mapper.readValue(字符串, javabean.class);

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

​​


Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.util.DefaultPrettyPrinter$In

整合ssm时踩过的坑Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.util.DefaultPrettyPrinter$Indenter直接说原因

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowErr

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.util.ArrayList[1]-添加@JsonBackReference

JsonParseException: Unexpected character ('?' (code 239)): was expecting comma to separate OBJECT en

今天调试一个数据上传功能,以json字符串上传,后台进行处理,测试的时候后台报错:JsonParseException: Unexpected character ('?' (code 239)): was expecting comma to separate OBJECT entries修改代码、修改http头,等等,折腾了半天还是没看出什么名堂来。后来仔细想想,既然提示是js

Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.dataformat.yaml.YAMLFactory

Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.dataformat.yaml.YAMLFactory。 解决办法:缺少jackson-dataformat-yaml-2.9.9.jar ...

【Java】Solr || 异常: Caused by: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion

1、完整异常19:29:29.919 [http-nio-8419-exec-1] ERROR c.h.s.h.GlobalExceptionHandler - [handleException,34] - handleException(),未知异常-异常捕获,errMsg:Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerialize

前言引入jar包报错Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer原因jar包版本不兼容解决首先查看自己的Spring版本​​​spring-boot-starter-parent​​<parent> <groupI

java.lang.NoClasjava.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException异常

java.lang.NoClasjava.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException异常解决方案:在pom.xml中添加依赖: <dependency> <groupId>com.fast

Failed to read artifact descriptor for com.fasterxml.jackson.core:jackson-databind:jar:2.9.0-SNAPSHO

http://stackoverflow.com/questions/42386730/issue-with-maxmind-dependency <dependency> <groupId>com.maxmind.db</groupId> <artifactId>maxmind-db</artifactId> <version>1.2.1</

Tomcat中jackson转换时jackson.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMap问题

首先一个是要保证导入正确的jar包,jackson转换需要三个jar包其次是要保证导入jar包的版本要一致,三个jar包版本不一致的话冲突,所以要保证jar包版本的一致https://mvnrepository.com/artifact/com.fasterxml.jackson.core这里附上下载连接...