Search in sources :

Example 86 with JSONObject

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;
}
Also used : JSONObject(net.sf.json.JSONObject) FlexClass(org.jaffa.flexfields.FlexClass) JSONObject(net.sf.json.JSONObject)

Example 87 with JSONObject

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);
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) JSONObject(net.sf.json.JSONObject) JsonConfig(net.sf.json.JsonConfig) InvalidParameterException(java.security.InvalidParameterException) AccessControlException(java.security.AccessControlException)

Example 88 with JSONObject

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";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.zsm.ssh.model.User) JSONObject(net.sf.json.JSONObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) Action(org.apache.struts2.convention.annotation.Action)

Example 89 with JSONObject

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);
}
Also used : CompositeInvocationHandlerImpl(com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) InvocationHandler(java.lang.reflect.InvocationHandler) HashMap(java.util.HashMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType) AdvisedSupport(org.springframework.aop.framework.AdvisedSupport)

Example 90 with JSONObject

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;
}
Also used : JSONObject(net.sf.json.JSONObject)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11