Examples of JSONAware


Examples of com.alibaba.fastjson.JSONAware

    public static JSONAwareSerializer instance = new JSONAwareSerializer();

    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
        SerializeWriter out = serializer.getWriter();

        JSONAware aware = (JSONAware) object;
        out.write(aware.toJSONString());
    }
View Full Code Here

Examples of com.alibaba.fastjson.JSONAware

        Assert.assertEquals("{}", serializer.getWriter().toString());
    }

    public void test_3() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        serializer.write(new JSONAware() {

            public String toJSONString() {
                return "null";
            }
        });
View Full Code Here

Examples of com.alibaba.fastjson.JSONAware

        Assert.assertEquals("null", serializer.getWriter().toString());
    }

    public void test_3_s() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        serializer.write(new JSONAware() {

            public String toJSONString() {
                return "null";
            }
        });
View Full Code Here

Examples of com.alibaba.fastjson.JSONAware

    public static JSONAwareSerializer instance = new JSONAwareSerializer();

    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.getWriter();

        JSONAware aware = (JSONAware) object;
        out.write(aware.toJSONString());
    }
View Full Code Here

Examples of com.alibaba.fastjson.JSONAware

        Assert.assertEquals("{}", serializer.getWriter().toString());
    }

    public void test_3() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        serializer.write(new JSONAware() {

            public String toJSONString() {
                return "null";
            }
        });
View Full Code Here

Examples of com.alibaba.fastjson.JSONAware

        Assert.assertEquals("null", serializer.getWriter().toString());
    }

    public void test_3_s() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        serializer.write(new JSONAware() {

            public String toJSONString() {
                return "null";
            }
        });
View Full Code Here

Examples of org.json.simple.JSONAware

    }

    @Override
    @SuppressWarnings({ "PMD.AvoidCatchingThrowable", "PMD.AvoidInstanceofChecksInCatchClause" })
    public void handle(HttpExchange pExchange) throws IOException {
        JSONAware json = null;
        URI uri = pExchange.getRequestURI();
        ParsedUri parsedUri = new ParsedUri(uri,context);
        try {
            // Check access policy
            InetSocketAddress address = pExchange.getRemoteAddress();
            requestHandler.checkClientIPAccess(address.getHostName(),address.getAddress().getHostAddress());
            String method = pExchange.getRequestMethod();

            // Dispatch for the proper HTTP request method
            if ("GET".equalsIgnoreCase(method)) {
                json = executeGetRequest(parsedUri);
            } else if ("POST".equalsIgnoreCase(method)) {
                json = executePostRequest(pExchange, parsedUri);
            } else {
                throw new IllegalArgumentException("HTTP Method " + method + " is not supported.");
            }
            if (backendManager.isDebug()) {
                backendManager.info("Response: " + json);
            }
        } catch (Throwable exp) {
            JSONObject error = requestHandler.handleThrowable(
                    exp instanceof RuntimeMBeanException ? ((RuntimeMBeanException) exp).getTargetException() : exp);
            json = error;
        } finally {
            sendResponse(pExchange,parsedUri, json.toJSONString());
        }
    }
View Full Code Here

Examples of org.json.simple.JSONAware

            throws IOException {
        if (backendManager.isDebug()) {
            logHandler.debug("URI: " + pUri);
        }

        JSONAware jsonRequest = extractJsonRequest(pInputStream,pEncoding);
        if (jsonRequest instanceof List) {
            List<JmxRequest> jmxRequests = JmxRequestFactory.createPostRequests((List) jsonRequest,pParameterMap);

            JSONArray responseList = new JSONArray();
            for (JmxRequest jmxReq : jmxRequests) {
                if (backendManager.isDebug()) {
                    logHandler.debug("Request: " + jmxReq.toString());
                }
                // Call handler and retrieve return value
                JSONObject resp = executeRequest(jmxReq);
                responseList.add(resp);
            }
            return responseList;
        } else if (jsonRequest instanceof Map) {
            JmxRequest jmxReq = JmxRequestFactory.createPostRequest((Map<String, ?>) jsonRequest,pParameterMap);
            return executeRequest(jmxReq);
        } else {
            throw new IllegalArgumentException("Invalid JSON Request " + jsonRequest.toJSONString());
        }
    }
View Full Code Here

Examples of org.json.simple.JSONAware

        handle(httpPostHandler,req,resp);
    }

    @SuppressWarnings({ "PMD.AvoidCatchingThrowable", "PMD.AvoidInstanceofChecksInCatchClause" })
    private void handle(ServletRequestHandler pReqHandler,HttpServletRequest pReq, HttpServletResponse pResp) throws IOException {
        JSONAware json = null;
        try {
            // Check access policy
            requestHandler.checkClientIPAccess(pReq.getRemoteHost(),pReq.getRemoteAddr());

            // Dispatch for the proper HTTP request method
            json = pReqHandler.handleRequest(pReq,pResp);
            if (backendManager.isDebug()) {
                backendManager.debug("Response: " + json);
            }
        } catch (Throwable exp) {
            JSONObject error = requestHandler.handleThrowable(
                    exp instanceof RuntimeMBeanException ? ((RuntimeMBeanException) exp).getTargetException() : exp);
            json = error;
        } finally {
            String callback = pReq.getParameter(ConfigKey.CALLBACK.getKeyValue());
            if (callback != null) {
                // Send a JSONP response
                sendResponse(pResp, "text/javascript",callback + "(" + json.toJSONString() ");");
            } else {
                sendResponse(pResp, "text/plain",json.toJSONString());
            }
        }
    }
View Full Code Here

Examples of org.json.simple.JSONAware

    /** {@inheritDoc} */
    @Override
    Object convertToObject(CompositeType pType, Object pFrom) {
        // break down the composite type to its field and recurse for converting each field
        JSONAware value = toJSON(pFrom);
        if (!(value instanceof JSONObject)) {
            throw new IllegalArgumentException(
                    "Conversion of " + value + " to " +
                    pType + " failed because provided JSON type " + value.getClass() + " is not a JSONObject");
        }

        Map<String, Object> givenValues = (JSONObject) value;
        Map<String, Object> compositeValues = new HashMap<String, Object>();

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.