代码如下:
/** * 把json转换成Record对象 * @Title jsonToRecord * @Description TODO * @param rec * @param columnName * @return * @since 2017年11月8日 上午11:39:36 */ @SuppressWarnings("unchecked") public static Record jsonToRecord(String jsonStr,String columnName){ Map<String, Object> columns= com.jfinal.json.FastJson.getJson().parse(jsonStr, Map.class);//这个异常 // Map<String, Object> columns= JSON.parseObject(jsonStr, Map.class);//把FastJson里面封装的提出来后就不会报错 Record record=new Record().setColumns(columns); return record; }
异常问题如下:
[ERROR]-[Thread: qtp667346055-22 - /weapons]-[com.jfinal.core.ActionHandler.handle()]: /weapons java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.jfinal.aop.Invocation.invoke(Invocation.java:87) at com.softisland.common.Interceptors.LeftMenuInterceptors.intercept(LeftMenuInterceptors.java:24) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.plugin.activerecord.tx.TxByActionKeys.intercept(TxByActionKeys.java:57) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.plugin.activerecord.tx.TxByMethods.intercept(TxByMethods.java:57) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.plugin.activerecord.tx.TxByMethodRegex.intercept(TxByMethodRegex.java:61) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.plugin.activerecord.tx.TxByActionKeyRegex.intercept(TxByActionKeyRegex.java:61) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.softisland.common.Interceptors.LeftMenuInterceptors.intercept(LeftMenuInterceptors.java:24) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.softisland.common.Interceptors.LoginInterceptors.intercept(LoginInterceptors.java:20) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:83) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:361) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.jfinal.aop.Invocation.invoke(Invocation.java:73) ... 42 more Caused by: java.lang.NoSuchMethodError: com.alibaba.fastjson.serializer.SerializeConfig.put(Ljava/lang/reflect/Type;Lcom/alibaba/fastjson/serializer/ObjectSerializer;)Z at com.jfinal.json.FastJson.<clinit>(FastJson.java:31) at com.softisland.utils.Constant.jsonToRecord(Constant.java:76) at com.softisland.business.weapons.service.BusinessWeaponsService.reloadRecord(BusinessWeaponsService.java:58) at com.softisland.business.weapons.service.BusinessWeaponsService.getListByPage(BusinessWeaponsService.java:38) at com.softisland.business.weapons.controller.BusinessWeaponsController.index(BusinessWeaponsController.java:60) ... 47 more
我在其他项目上使用的同样的方法,同样的json就不会报错,各种清理,各种干就是不对,始终找不到原因,最后无赖;
解决办法就是:只有把jfinal里面封装的方法实现的代码复制出来后直接使用就不会报错了;求讲解原因@jfinal