在Java代理中,我想使用GSON来解析json。但是当我尝试:
String jsonReceived = "{'product':'IBM Domino','args':{'since':'1970','current':'9.0.2'}}";
Product product = (Product) gson.fromJson(jsonReceived, Product.class);
我收到消息:
java.security.AccessControlException:拒绝访问(“java.lang.reflect.ReflectPermission”“suppressAccessChecks”)
我最近将java策略更改为max:
grant {
permission java.security.AllPermission;
}
那么是什么限制了我?
以下是完整的代码:
import lotus.domino.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
public class JavaAgent extends AgentBase {
public void NotesMain() throws JsonParseException{
String msg = null;
lotus.domino.Session session = getSession();
OpenLogItem oli = new OpenLogItem(session);
try {
AgentContext agentContext = session.getAgentContext();
msg = "Agent " + agentContext.getCurrentAgent().getName() + " using runtime version:" + System.getProperty("java.runtime.version");
oli.logEvent(msg, OpenLogItem.SEVERITY_LOW, null);
Gson gson = new GsonBuilder().create();
msg = "after new Gson()";
oli.logEvent(msg, OpenLogItem.SEVERITY_LOW, null);
String jsonReceived = "{'product':'IBM Domino'}";
Product product = (Product) gson.fromJson(jsonReceived, Product.class);
msg = "after gson.fromJson";
oli.logEvent(msg, OpenLogItem.SEVERITY_LOW, null);
} catch(Exception e) {
oli.logError(e);
}
}
public class Product{
String product;
String msg = null;
lotus.domino.Session session = getSession();
OpenLogItem oli = new OpenLogItem(session);
public Product(){
msg = "Product() // constructor";
oli.logEvent(msg, OpenLogItem.SEVERITY_LOW, null);
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
/*@Override
public String toString() {
// TODO Auto-generated method stub
return "product: " + getProduct();
}*/
}
}
答案 0 :(得分:1)
我刚刚使用Java代理程序通过GSON解析JSON。得到了同样的错误,创建了具有相同完全权限的java.pol文件并且它有效。请记住设置安全性以允许代理
上的受限操作