jackson 解析json报错:Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

Invalid JSON input: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nes 今天遇到一个报错信息: org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException 阅读详情
AI摘要

本文详细解析了在使用Jackson库进行JSON解析时遇到的MismatchedInputException异常,该异常源于JSON结构与预期的String类型不匹配。文章提供了两种解决方案:一是创建与errorInfo字段对应的类;二是若该字段无实际用途,则直接从bean对象中移除,以避免解析错误。

一问题

  Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
 at [Source: (String)"{"code":500,"data":null,"errorInfo":{"code":500,"data":null,"date":1592810896632,"msg":"XX失败"},"msg":"XX失败"}"; line: 1, column: 37] (through reference chain: com..XX..["errorInfo"])
    at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
    at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1139)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1093)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:63)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:10)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004)
    at com.benmu.api.json.JsonUtil.of(JsonUtil.java:112)
    ... 78 common frames omitted

我再调用三方接口的时候,返回的json要解析成bean对象XXresp,正常的情况下,errorInfo为null 不报错。

异常情况下这个异常信息解析失败。这个沿用了工程中的jackson方式解析JSON:

XXresp 对应的字段为String类型。

二 解决:

 这个报错跟哪个缺少无参构造器导致无法实例化的报错还是有明显区别的。

就是类型不对,返回的是JSON,String处理不了。

方法1

加个类,属性呢跟errorInfo 对应上。

方法2:

 如果确定没啥用途,解析用不到,可以直接删除掉。

亲测两种方式都好使。

 

【异常】Jackson序列化提示Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; 摘要: JSON反序列化错误源于EnglishStudyReq类的parameters字段类型与实际请求不匹配。日志显示Jackson无法将JSON对象转为String类型。解决方案:1) 推荐将parameters改为Map<String,Object>或自定义实体类以匹配JSON对象结构;2) 若需保留String类型,请求中需传递转义后的JSON字符串(如"{\"key\":\"value\"}")。类型定义与实际数据结构一致是解 阅读详情

相关推荐

su03t语音模块烧录识别不出问题解决方法

su03t语音sdk烧录无法识别问题

weixin_49387645的博客 6389

Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

测试遇到报错: {"data":null,"status":500,"error":"JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.

weixin_43866043的博客 1万+

app逆向分析案例-95分

先把justtrusmeplus打开设置好95分,开始抓包,得到结果为: https://www.95fenapp.com/api_goods/list/v3.0?is_all=1&keywords=%E7%A7%91%E6%AF%94& page=1&page_size=20 &publish_timestamp=0 &scene=2&scene_type=95fen_android_search_personal&sn=SearchList

weixin_41763171的博客 2742

JSON转换异常:Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

其实给出的提示已经很明确了:比如:Cannot deserialize instance of:无法反序列化,比如:through reference chain:指的就是这个参数的类型有问题,这里我这个 data 是一个 String 类型,但是三方返回的格式是这样的:{laoliu:xxxx}

欢迎来到 ABin-阿斌的博客:写一生代码,创一世佳话,筑一览芳华。 1万+

数电实验,如何安装Quartus II软件?

数电实验第一步,安装软件Quartus II! 安装这个软件可以说是很折磨我了,依然是failed很多次之后终于可以了! 能成功安装,多亏了网络上的各路大神!!!不胜感激 现在分享经验如下: ps:我分享的是Quartus II 14.0版本的软件及破解器安装使用方法 注意!想要在电脑上顺利安装,前提条件是电脑有10G以上内存!!! 友情提示:建议整个下载过程中,提前关掉所有杀毒、电脑

一个程序媛的成长记录❤ 3653

优快云专栏限时活动!福利公告必读!

本人优快云付费专栏周排名27名专业博主,每周文章平均阅读量约7w以上!

FJN110的博客 3153

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList out of VALUE_STRING token 原因: 页面传参json数组字符串,导致后台spring无法解析,例如:[{“name”: “1”}, {“name”: “2”}] 解决方法: 把json字符串,转换为json对象。 把 {attributes

Smilelfq的专栏 2万+

HBV模型

据说mHM模型也是基于HBV模型原理。 网上不同版本的HBV模型稍有差别 def hbv_main(n_days, params, air_temp, prec, dpem): #n_days 模拟天数 #air_temp 每月温度 #prec 降水 #dpem 每月蒸发 Tsnow_thresh = 0.0 ca = 410. # Initialize arrays for the simiulation snow = np.zeros(air_temp.size

m0_46268055的博客 2326

Cannot deserialize instance of java.lang.String out of START_ARRAY/START_OBJECT token,RestTemplate小坑

Jackson,Spring MVC,RestTemplate,START_OBJECT,START_ARRAY

layne的博客 1万+

【即插即用模块】注意力篇 | TGRS 2025 | SPR:显著性比例协调,注意力聚焦,先抓差异再精准特征融合!

本文提出SPRMamba网络中的显著性比例协调模块(SPR),用于解决遥感变化检测中非显著变化区域的识别难题。该模块通过差异提取→显著性识别→比例融合的三步流程,动态平衡显著与非显著特征表示。SPR包含空间滤波(SF)和上下文记忆(CMM)两个子模块,分别基于统计特征和深度学习自动区分特征差异中的显著性成分。实验表明,SPR能有效抑制背景噪声干扰,提升边缘检测精度,且随着模块数量的增加,模型性能持续改善。该模块计算成本低,可直接嵌入双输入特征融合场景,适用于各类需要动态特征平衡的视觉任务。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 364

UDS诊断服务基础详解之二19服务

本文主要介绍UDS统一诊断服务的19 01服务,包含状态位和故障码的解析以及19 01服务的具体说明

车载网络小D的博客 1万+

Java Cannot deserialize instance of `xxx` out of START_ARRAY token问题2种情况解决(Java、Jackson)

问题描述: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot

旭东怪的博客 3万+

构建.NET网站:VSCode还是Visual Studio?揭开开发工具的选择之谜

选择VSCode还是Visual Studio,归根结底是取决于你的具体需求和偏好。🔍 这两款工具各有千秋,都能为你的.NET网站开发提供强大的支持。希望这篇文章能够帮助你更全面地了解这两款工具,做出明智的选择。

墨夶的博客 787

Java监听rabbitmq消息报错:Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

摘要:SpringBoot项目在拆分为Dubbo微服务后,RabbitMQ消息监听报错,提示无法将JSON对象反序列化为String。原因为Dubbo自动配置将消息转换器从SimpleMessageConverter替换为Jackson2JsonMessageConverter。解决方案是恢复使用SimpleMessageConverter,通过配置自定义容器工厂或直接声明SimpleMessageConverter Bean,使消息体直接转为字符串,保持与原有逻辑一致。

yanghaitao5000的博客 198

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

json数组在后台解析失败Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList out of START_OBJECT token 原因: json数组在后台解析失败 解决方法: json数组,在后台接收时,必须把List集合放入另一个java对象中。 也就是说,后台不能接收json数组[],只能接收json对象{}。 把 public Glo

公z号:职场爱学习 8546

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token解决方法

项目场景: 报错的原因:一系列的报错,如:Cannot deserialize instance of `java.lang.Integer`out of START_OBJECT token等错误,都是相同的原因。前端传入的是JSON格式,后端无法将接收到的JSON字符串转化为对应的数据格式,故而爆出这样的错误。 原因分析: 既然咱们项目正在使用的框架无法将数据转化为成我们需要的格式,那我们可以自己手动去转化 解决方案: 下图即为将前端JSON数据转化为我们想要的集合格式,当然了其它的.

漫观天上云卷云舒的博客 4万+

Cannot deserialize instance of `java.lang.String` out of START_OBJECT token at

map toString

一路向前 3275

Can not deserialize instance of java.lang.String out of START_OBJECT token 问题处理办法

核对数据格式:前端发送的JSON结构需与后端参数类型一致。选择调整策略:优先统一前后端数据类型(如均使用对象或字符串)。验证修复效果:通过日志或调试工具确认反序列化成功。通过以上方法,可系统性解决JSON解析类型冲突问题。若需进一步调试,建议结合具体代码场景分析。

码觉客的博客 2019

Rest接口请求报错Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

2、如果是入参是集合类型,入参值类型与入参要求的泛型类型不一致。1、入参值类型与入参要求的类型不一致。请求发送接口,报如下异常信息。

hkl_Forever的博客 2379

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `com.

异常:MismatchedInputException 原因:请求服务器获得响应数据为jSON集合,而接收是对象类型 修复:把对象类型修改List.class就能解决

baobaobeibei888的博客 1万+

Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token at [Source: (String)"{"a":"hnsdklnd","b":[]}"; line: 1, column...

qq_38621053的博客 6万+

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of 错误

1. 错误信息: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList<com.chaz.weather.bean.Yesterday> out of START_OBJECT token 踩坑: SpringBoot...

星辰里的月光 3万+

com.fasterxml.jackson.databind.exc.MismatchedInputException

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token 请求参数匹配导致的异常 后台用的是字符串接收,这里传的是数组,所有出现异常,值的最外层加上引号即可 注意事项:当存储的是json 字符串的情况,需要注意 最外层用了引号的情况下,里面用的转义符 " \ " ..

zhongyuan_p的博客 2万+

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `org.springframework.security.core.authority.SimpleGrantedAuthority` (although at least one Creator exists): cannot deserialize from Object value

SYWL的博客 9384
上一篇: 奈学公开课RocketMq学习笔记二
下一篇: Elasticsearch核心技术与实战学习笔记 37 | 集群分布式模型及选主与脑裂问题
bohu83
博客等级 码龄20年 1923粉丝 978原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bohu83

买个馒头吃

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值