控制器返回Json 调用方法renderJson(gbo)出现异常

控制器写法:

image.png

对model


image.png

配置:

image.png

报如下错误:

java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.shop.model.ImsZofuiSalesGood and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

at com.jfinal.json.Jackson.toJson(Jackson.java:93)

at com.jfinal.kit.JsonKit.toJson(JsonKit.java:28)

at com.jfinal.render.JsonRender.<init>(JsonRender.java:125)

at com.jfinal.render.RenderFactory.getJsonRender(RenderFactory.java:103)

at com.jfinal.core.Controller.renderJson(Controller.java:1133)

at com.shop.blog.TestController.findById(TestController.java:14)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at com.jfinal.aop.Invocation.invoke(Invocation.java:75)

at com.jfinal.plugin.activerecord.tx.TxByActionKeys.intercept(TxByActionKeys.java:57)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.jfinal.plugin.activerecord.tx.TxByActionKeyRegex.intercept(TxByActionKeyRegex.java:61)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.jfinal.plugin.activerecord.tx.TxByMethods.intercept(TxByMethods.java:57)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.jfinal.plugin.activerecord.tx.TxByMethodRegex.intercept(TxByMethodRegex.java:61)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:81)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:86)

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)


评论区

84740165

2019-03-08 12:16

大神帮忙看下!

JFinal

2019-03-08 14:21

jackson 是根据 getter 方法来转 jsonString 的,而你的 Model 没有生成 getter 方法

下载首页的 jfinal demo for maven,直接用上里面的一个生成器,生成 getter 方法即可

如果不想生成,使用:
me.setJsonFactory(new MixedJsonFactory());

注意看一下 json 相关文档:
https://www.jfinal.com/doc/12-1

84740165

2019-03-11 11:42

热门反馈

扫码入社