Could not write JSON: JsonObject; nested exception is com.fasterxml.jackson.databind.JsonMappingExce

 

一、错误标题:

Could not write JSON: JsonObject; nested exception is com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.dandan.response.AppResponseData[\"data\"]->com.google.gson.JsonObject[\"asString\"])

二、错误原文:

{
    "timestamp": "2019-05-07T12:08:43.435+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Could not write JSON: JsonObject; nested exception is com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.dandan.response.AppResponseData[\"data\"]->com.google.gson.JsonObject[\"asString\"])",
    "path": "/pay/createPayToken"
}

三、错误原图

PS:(来自PostMan接口测试工具截图)

四、错误解释:

译文:无法编写JSON: JsonObject;嵌套异常是com.fasterxml.jackson.databind.JsonMappingException: JsonObject(通过引用链:com.dandan.response.AppResponsedata [\"data\"]->com.google.gson.JsonObject[\"asString\"])
 

解释:意思其实没什么意思,就是无法编写JSON,或者说进行将返回值封装成JSON并返回这么个操作后报错。

com.fasterxml.jackson.databind.JsonMappingException:     这个是指报的错误,通过该错误百度很难找到符合的解决方案

那么看后面的提示语句:

JsonObject(通过引用链: com.dandan.response.AppResponsedata [\"data\"]->com.google.gson.JsonObject[\"asString\"])

这一串代表了错误来源,我这边是一个AppResponsedata类是一个接口返回数据封装类,该错误代表封装类去装载返回数据时报错。

返回时的封装代码:

return new AppResponseData(ResultCode.SUCCESS, jsonObject);

原因就出现在将返回数据封装成JSON时我们使用了

来源于com.google.gson.JsonObjec的JSONObject类对象,

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key","value");

五、错误解决

实际上我们应该支持国产货,选择来源于Alibaba的JSONObject类 

附上全导包名:

import com.alibaba.fastjson.JSONObject;
JSONObject jsonObject = new JSONObject();
jsonObject.put("payToken", payToken);

通过该类封装数据为JSON并返回即可。

返回值为:

六、末尾说明

关于一种错误,引发有多重形式,但如果错误前缀是:

Could not write JSON: JsonObject; nested exception is com.fasterxml.jackson.databind.JsonMappingException:

通常都是又封装JSON时引发的错误,细心检查,相信很快就能解决的呢!

 

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.alibaba.fastjson.JSONObject["file"]->org.springframework.core.io.ByteArrayResource["inputStream"]) at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:284) at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110) at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135) at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69) at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:689) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:633) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:536) at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:30) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:2509) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.writeInternal(MappingJackson2HttpMessageConverter.java:141)
06-15

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值