转自:http://www.cnblogs.com/xiaoyaorensheng/archive/2013/01/02/2842302.html
偶遇一个问题:org.apache.struts2.json.JSONWriter can not access a member of class
org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
with modifiers "public"。困扰了半天,找到了解决方案,写写自己的一些理解。
action代码:
1 package edu.bjfu.action;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.annotation.Resource;
7
8 import org.apache.struts2.json.annotations.JSON;
9
10
11 import com.opensymphony.xwork2.ActionSupport;
12
13 import edu.bjfu.entity.Authority;
14 import edu.bjfu.service.AuthorityService;
15
16 public class AuthoritiesAction extends ActionSupport{
17 private AuthorityService authorityService;
18 private List<Authority> authorities;
19
20 public List<Authority> getAuthorities() {
21 return authorities;
22 }
23
24 public void setAuthorities(List<Authority> authorities) {
25 this.authorities = authorities;
26 }
27 public AuthorityService getAuthorityService() {
28 return authorityService;
29 }
30
31 @Resource(name="authorityService")
32 public void setAuthorityService(AuthorityService authorityService) {
33 this.authorityService = authorityService;
34 }
35
36 public String execute() throws Exception {
37 authorities=authorityService.getAllAuthorities();
38 return SUCCESS;
39 }
40
41 }
配置文件代码:
1 <package name="super_admin" extends="json-default" namespace="/superadmin">
2 <action name="allAuthorities" class="edu.bjfu.action.AuthoritiesAction">
3 <result type="json"></result>
4 </action>
5 </package>
ajax交互代码:
1 $(function(){
2 $.post("superadmin/allAuthorities?dt="+new Date().getTime(),
3 function(data){
4 $("#authority").empty();
5 var json = eval(data);
6 for(var i=0;i<json.length;i++){
7 $("#authority").append("<option value='"+json[i].authorityId+"'>"+json[i].authorityName+"</option>");
8 }
9 },"json")
10 })
这样每次在交互的时候就会发生以上错误。
主要原因:struts会将action中定义的一些变量序列化转换成json格式,需要调用对象的一系列get方法(例子中调用authorityService和authorities的get方法),并调用以上两个变量的成员变量的get方法将其内容组成json格式。但是在序列化authorityService时,由于其成员变量中含有含有接口所以会报错。
解决方案:
1)修改配置文件:指定序列化的根节点,这样data就是从authorities的根节点以下的数据,不需要用data.authorities
1 <package name="super_admin" extends="json-default" namespace="/superadmin">
2 <action name="allAuthorities" class="edu.bjfu.action.AuthoritiesAction">
3 <result type="json"><param name="root">authorities</param></result>
4 </action>
5 </package>
2) 修改java代码:让编译器不对authorityService序列化
1 @JSON(serialize=false)
2 public AuthorityService getAuthorityService() {
3 return authorityService;
4 }
分享到:
相关推荐
包含以下java源文件: com.google.gson.DefaultDateTypeAdapter.class com.google.gson.ExclusionStrategy.class ...com.google.gson.stream.JsonWriter.class com.google.gson.stream.MalformedJsonException.class
org.json全部源代码 1、CDL.java 2、Cookie.java 3、CookieList.java 4、HTTP.java 5、HTTPTokener.java 6、JSONArray.java 7、JSONException.java 8、JSONML.java 9、JSONObject.java 10、JSONString.java 11、...
java 工具包, async-...com.google.gson.stream.JsonWriter.class com.google.gson.stream.MalformedJsonException.class com.google.gson.stream.StringPool.class
- Attributes like JsonIgnore and JsonProperty can be added to a class to customize how a class is serialized - Ability to convert JSON to and from XML Instructions: 1. Extract Newtonsoft.Json....
使用纯C++编写的json解析文件,此文件解析速度快
JsonWriter
第一种通过JsonReader和JsonWriter两个对象进行json文件的读写操作,需要sdk在11以上。 第二种通过JSONArray、JSONObject、JSONTokener等对象进行json读写操作,需要sdk在9以上。这种方式也可通过引入jar包的方式在...
修改后的JSONWriter类,相信请见
Solidity JSON 编写器 一个帮助生成和构建用于智能合约开发的 JSON 的库。... using JsonWriter for JsonWriter.Json; function generateJSON () external pure returns ( string memory ) { JsonWri
jsonwriter :功能模块,用于 该模块为使用应用程序编写 JSON 提供了一个简单的框架。 它包含许多用于正确生成适当转义的 JSON 的辅助方法。 此模块的 API 尚不稳定。 示例用户是通过使用模块。 兼容性 标签与 ...
json依赖jar包json依赖jar包json依赖jar包json依赖jar包json依赖jar包json依赖jar包
通过2-jsonwriter 将 JSON 字符串化的简单转换流 安装 npm install through2-jsonwriter 或者 npm install --save through2-jsonwriter 用法 var jsonWriter = require ( 'through2-jsonwriter' ) ; var ...
.NET的LaunchDarkly流JSON总览LaunchDarkly.JsonStream库实现了一种针对JSON编码和解码的流传输方法,旨在实现高效率(假设文本编码为UTF8)。 与基于反射的框架不同,它不了解结构或其他复杂类型。 您必须明确告诉...
(https://doris.apache.org/zh-CN/docs/ecosystem/datax?_highlight=datax#%E5%85%B3%E4%BA%8E-datax) DataX Web是在DataX之上开发的分布式数据同步工具,提供简单易用的 操作界面。 GitHub上的Datax Web项目不支持...
基于C#实现的对Json进行格式化字符串解析的.NET类库源码V3.0.
JsonWriter :用于生成JSON的构建器样式的API。 JsonReader :解析JSON并构建JsonValue对象的DOM。 JsonValue :描述JSON对象,数组,字符串,float,long,boolean或null。 Json :使用JsonReader和JsonWriter...
使用liburl动态库 上传文件和字符串,在windows 自己摸索的,并非C语言实现。C++ MFC实现
从文件或流中读取和写入JSON数据。 通过JsonSchema进行验证(有关规范,请参见http://json-schema.org)
java编程,对json文件进行读写操作,需要引用的jar包。
Json.NET只提供了服务器端的方法,主要有实现JSON文本与XML互相转换的类,有自定义读写JSON的JsonReader类和JsonWriter类,还有一个非自定义读写JSON的JavaScriptSerializer类。 ASP.NET AJAX中,服务器端由...