use of net.sf.json.JSONObject in project jaffa-framework by jaffa-projects.
the class ExcelExportService method jsonToBean.
/**
* Converts the input JSON structure into an instance of the beanClassName.
* If the beanClassName is null, then an instance of org.apache.commons.beanutils.DynaBean will be returned.
*
* @param input
* input as a JSON structure.
* @param beanClassName
* the name of the bean class.
* @return the input JSON structure as an instance of the beanClassName.
* @throws ClassNotFoundException if the beanClassName is invalid.
*/
public static Object jsonToBean(String input, String beanClassName) throws ClassNotFoundException {
if (log.isDebugEnabled())
log.debug("Converting JSON '" + input + "' into an instance of " + beanClassName);
registerCustomMorphers();
Class beanClass = beanClassName != null ? Class.forName(beanClassName) : null;
JSONObject jsonObject = JSONObject.fromObject(input);
Object bean = JSONObject.toBean(jsonObject, createJsonConfig(beanClass));
if (log.isDebugEnabled())
log.debug("Converted to: " + bean);
return bean;
}
use of net.sf.json.JSONObject in project jaffa-framework by jaffa-projects.
the class JaffaComponentHelper method validateJSONObject.
/**
* Validates the JSONObject class name.
*
* @param className <code>String</code> the class name.
* @param value <code>String</code> the request parameter value.
* @param error <code>String</code> the error message.
* @throws <code>InvalidParameterException</code> the exception, designed
* for use by the JCA/JCE engine classes, is thrown when an invalid
* parameter is passed to a method.
*/
private void validateJSONObject(final String className, final String value, final String error) throws InvalidParameterException {
try {
final Class<?> clazz = Class.forName(className);
clazz.newInstance();
try {
final JSONObject json = JSONObject.fromObject(value);
final JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setRootClass(clazz);
JSONSerializer.toJava(json, jsonConfig);
} catch (Exception e) {
throw new InvalidParameterException(error);
}
} catch (ClassNotFoundException e) {
throw new InvalidParameterException(error);
} catch (InstantiationException e1) {
throw new InvalidParameterException(error);
} catch (IllegalAccessException e1) {
throw new InvalidParameterException(error);
}
}
use of net.sf.json.JSONObject in project Resource by lovelifeming.
the class UserAction method execute.
// @Action(value="login")
@Action(value = "login", results = { @Result(name = "success", location = "/success.jsp", params = { "resultJson", "resultJson" }), @Result(name = "error", location = "/error.jsp") })
public String execute() throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
JSONObject result = new JSONObject();
User user = userService.getByName(username);
result.put("user", user);
if (user != null && user.getUser_name().equals(username) && user.getPassword().equals(password)) {
result.put("message", "登录成功");
result.put("status", "true");
resultJson = result.toString();
request.setAttribute("resultJson", resultJson);
writeResponseData(request, response, result);
return "success";
}
result.put("message", "登录失败");
result.put("status", "false");
resultJson = result.toString();
writeResponseData(request, response, result);
return "error";
}
use of net.sf.json.JSONObject in project ysoserial by frohoff.
the class JSON1 method makeCallerChain.
/**
* Will call all getter methods on payload that are defined in the given interfaces
*/
public static Map makeCallerChain(Object payload, Class... ifaces) throws OpenDataException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
CompositeType rt = new CompositeType("a", "b", new String[] { "a" }, new String[] { "a" }, new OpenType[] { javax.management.openmbean.SimpleType.INTEGER });
TabularType tt = new TabularType("a", "b", rt, new String[] { "a" });
TabularDataSupport t1 = new TabularDataSupport(tt);
TabularDataSupport t2 = new TabularDataSupport(tt);
// we need to make payload implement composite data
// it's very likely that there are other proxy impls that could be used
AdvisedSupport as = new AdvisedSupport();
as.setTarget(payload);
InvocationHandler delegateInvocationHandler = (InvocationHandler) Reflections.getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as);
InvocationHandler cdsInvocationHandler = Gadgets.createMemoizedInvocationHandler(Gadgets.createMap("getCompositeType", rt));
CompositeInvocationHandlerImpl invocationHandler = new CompositeInvocationHandlerImpl();
invocationHandler.addInvocationHandler(CompositeData.class, cdsInvocationHandler);
invocationHandler.setDefaultHandler(delegateInvocationHandler);
final CompositeData cdsProxy = Gadgets.createProxy(invocationHandler, CompositeData.class, ifaces);
JSONObject jo = new JSONObject();
Map m = new HashMap();
m.put("t", cdsProxy);
Reflections.setFieldValue(jo, "properties", m);
Reflections.setFieldValue(jo, "properties", m);
Reflections.setFieldValue(t1, "dataMap", jo);
Reflections.setFieldValue(t2, "dataMap", jo);
return Gadgets.makeMap(t1, t2);
}
use of net.sf.json.JSONObject in project summer-mis by cn-cerc.
the class AsyncService method read.
public AsyncService read(String jsonString) {
JSONObject json = JSONObject.fromObject(jsonString);
this.setService(json.getString("service"));
if (json.containsKey("dataOut"))
this.getDataOut().setJSON(json.getString("dataOut"));
if (json.containsKey("dataIn"))
this.getDataIn().setJSON(json.getString("dataIn"));
if (json.containsKey("process"))
this.setProcess(json.getInt("process"));
if (json.containsKey("timer"))
this.setTimer(json.getString("timer"));
if (json.containsKey("processTime"))
this.setProcessTime(json.getString("processTime"));
return this;
}
Aggregations