jboot切换fastjson后反序列化报错?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

jboot切换fastjson后反序列化报错?报错

2020-06-06 15:52:48 248 1

 @理工男海哥 执行以下代码时报错:

Class clazz = jsonObject.getObject("clazz", Class.class);

报错信息:

Caused by: com.alibaba.fastjson.JSONException: can not cast to : java.lang.Class

javax.servlet.ServletException: Filtered request failed.
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:384)
	at io.jboot.component.shiro.JbootShiroFilter.doFilterInternal(JbootShiroFilter.java:72)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
	at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
	at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
	at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
	at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
	at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: com.alibaba.fastjson.JSONException: can not cast to : java.lang.Class
	at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:804)
	at com.alibaba.fastjson.util.TypeUtils.castToJavaBean(TypeUtils.java:655)
	at com.alibaba.fastjson.JSONObject.getObject(JSONObject.java:139)
	at io.jboot.core.serializer.FastjsonSerializer.deserialize(FastjsonSerializer.java:37)
	at io.jboot.component.redis.JbootRedisBase.valueFromBytes(JbootRedisBase.java:59)
	at io.jboot.component.redis.jedis.JbootJedisImpl.get(JbootJedisImpl.java:189)
	at io.jboot.core.cache.redis.JbootRedisCacheImpl.get(JbootRedisCacheImpl.java:51)
	at io.jboot.component.shiro.cache.JbootShiroCache.get(JbootShiroCache.java:41)
	at org.apache.shiro.session.mgt.eis.CachingSessionDAO.getCachedSession(CachingSessionDAO.java:217)
	at org.apache.shiro.session.mgt.eis.CachingSessionDAO.getCachedSession(CachingSessionDAO.java:202)
	at org.apache.shiro.session.mgt.eis.CachingSessionDAO.readSession(CachingSessionDAO.java:259)
	at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSessionFromDataSource(DefaultSessionManager.java:236)
	at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSession(DefaultSessionManager.java:222)
	at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.doGetSession(AbstractValidatingSessionManager.java:118)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupSession(AbstractNativeSessionManager.java:148)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.getSession(AbstractNativeSessionManager.java:140)
	at org.apache.shiro.mgt.SessionsSecurityManager.getSession(SessionsSecurityManager.java:156)
	at org.apache.shiro.mgt.DefaultSecurityManager.resolveContextSession(DefaultSecurityManager.java:456)
	at org.apache.shiro.mgt.DefaultSecurityManager.resolveSession(DefaultSecurityManager.java:442)
	at org.apache.shiro.mgt.DefaultSecurityManager.createSubject(DefaultSecurityManager.java:338)
	at org.apache.shiro.subject.Subject$Builder.buildSubject(Subject.java:846)
	at org.apache.shiro.web.subject.WebSubject$Builder.buildWebSubject(WebSubject.java:148)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.createSubject(AbstractShiroFilter.java:292)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:359)
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-06 15:52:59
                        <p>不知道这个 class 字段存的是什么?建议存字符串,然后再通过 Class.forName(string) 得到具体的class。</p>
    
                    
    
                        <pre>Class clazz = jsonObject.getObject("clazz", Class.class);</pre> 
    

    修改为:

    String classString = jsonObject.getObject("clazz", String.class);
    Class clazz = Class.forName(classString)

     

                        <div class='ref'><h4>引用来自“理工男海哥”的评论</h4><pre>Class clazz = jsonObject.getObject("clazz", Class.class);</pre> 
    

    修改为:

    String classString = jsonObject.getObject("clazz", String.class);
    Class clazz = Class.forName(classString)

     

                            我的意思是jboot里fastjson反序列化,现在就是使用Class class = jsonObject.getObject("class",Class.class)取的
                        
    
                            这个应该和 jboot 无关吧
    
    0 0
相关问答

37

回答

阿里官方Java代码规范标准《阿里巴巴Java开发手册》下载

管理贝贝 2017-02-10 15:14:36 77764浏览量 回答数 37

2

回答

[@徐雷frank][¥20]在用fastjson将字符串转为JSONObject对象时,double类型被转为BigDecimal类型

jiang0512 2018-11-23 15:15:21 7074浏览量 回答数 2

1

回答

@ResponseBody与response.getWriter .write()区别

蛮大人123 2016-02-22 11:11:38 5145浏览量 回答数 1

2

回答

赛题一:《人机行为识别》大家写udf的时候是什么提取json数据啊

cj753733 2017-02-15 20:04:39 4694浏览量 回答数 2

2

回答

1.2.7版本fastjson转字符串后key的排序,如何能完全按字母顺序排列?

杨冬芳 2016-07-07 16:13:51 6922浏览量 回答数 2

2

回答

建议将aliyun-sdk-oss依赖的json-lib改成fastjson

咸鸭蛋 2015-11-30 16:43:48 6559浏览量 回答数 2

1

回答

为什么fastjson字段为null时不输出空字符串?

蛮大人123 2016-03-09 18:31:25 5526浏览量 回答数 1

2

回答

Redis存放java对象为何序列化?

落地花开啦 2016-02-20 15:07:44 8152浏览量 回答数 2

1

回答

fastjson在反序列化时怎么解析对象中的继承

蛮大人123 2016-02-28 14:02:57 4604浏览量 回答数 1

1

回答

fastJson如何将json字符串转为list<javaBean>

杨冬芳 2016-07-06 14:25:43 5202浏览量 回答数 1
+关注
爱吃鱼的程序员
https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
2
文章
21569
问答
问答排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载