Here are the examples of the java api class org.json.simple.JSONAware taken from open source projects.
1. CompositeTypeConverter#convertToObject()
Project: jolokia
File: CompositeTypeConverter.java
File: CompositeTypeConverter.java
/** {@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>(); fillCompositeWithGivenValues(pType, compositeValues, givenValues); completeCompositeValuesWithDefaults(pType, compositeValues); try { return new CompositeDataSupport(pType, compositeValues); } catch (OpenDataException e) { throw new IllegalArgumentException("Internal error: " + e.getMessage(), e); } }
2. ArrayTypeConverter#convertToObject()
Project: jolokia
File: ArrayTypeConverter.java
File: ArrayTypeConverter.java
/** {@inheritDoc} */ @Override public Object convertToObject(ArrayType type, Object pFrom) { JSONAware value = toJSON(pFrom); // prepare each value in the array and then process the array of values if (!(value instanceof JSONArray)) { throw new IllegalArgumentException("Can not convert " + value + " to type " + type + " because JSON object type " + value.getClass() + " is not a JSONArray"); } JSONArray jsonArray = (JSONArray) value; OpenType elementOpenType = type.getElementOpenType(); Object[] valueArray = createTargetArray(elementOpenType, jsonArray.size()); int i = 0; for (Object element : jsonArray) { valueArray[i++] = getDispatcher().convertToObject(elementOpenType, element); } return valueArray; }
3. JolokiaHttpHandler#doHandle()
Project: jolokia
File: JolokiaHttpHandler.java
File: JolokiaHttpHandler.java
@SuppressWarnings({ "PMD.AvoidCatchingThrowable", "PMD.AvoidInstanceofChecksInCatchClause" }) public void doHandle(HttpExchange pExchange) throws IOException { if (requestHandler == null) { throw new IllegalStateException("Handler not yet started"); } JSONAware json = null; URI uri = pExchange.getRequestURI(); ParsedUri parsedUri = new ParsedUri(uri, context); try { // Check access policy InetSocketAddress address = pExchange.getRemoteAddress(); requestHandler.checkAccess(getHostName(address), address.getAddress().getHostAddress(), extractOriginOrReferer(pExchange)); String method = pExchange.getRequestMethod(); // Dispatch for the proper HTTP request method if ("GET".equalsIgnoreCase(method)) { setHeaders(pExchange); json = executeGetRequest(parsedUri); } else if ("POST".equalsIgnoreCase(method)) { setHeaders(pExchange); json = executePostRequest(pExchange, parsedUri); } else if ("OPTIONS".equalsIgnoreCase(method)) { performCorsPreflightCheck(pExchange); } else { throw new IllegalArgumentException("HTTP Method " + method + " is not supported."); } } catch (Throwable exp) { json = requestHandler.handleThrowable(exp instanceof RuntimeMBeanException ? ((RuntimeMBeanException) exp).getTargetException() : exp); } finally { sendResponse(pExchange, parsedUri, json); } }
4. AgentServlet#handle()
Project: jolokia
File: AgentServlet.java
File: AgentServlet.java
@SuppressWarnings({ "PMD.AvoidCatchingThrowable", "PMD.AvoidInstanceofChecksInCatchClause" }) private void handle(ServletRequestHandler pReqHandler, HttpServletRequest pReq, HttpServletResponse pResp) throws IOException { JSONAware json = null; try { // Check access policy requestHandler.checkAccess(allowDnsReverseLookup ? pReq.getRemoteHost() : null, pReq.getRemoteAddr(), getOriginOrReferer(pReq)); // Remember the agent URL upon the first request. Needed for discovery updateAgentDetailsIfNeeded(pReq); // Dispatch for the proper HTTP request method json = handleSecurely(pReqHandler, pReq, pResp); } catch (Throwable exp) { json = requestHandler.handleThrowable(exp instanceof RuntimeMBeanException ? ((RuntimeMBeanException) exp).getTargetException() : exp); } finally { setCorsHeader(pReq, pResp); String callback = pReq.getParameter(ConfigKey.CALLBACK.getKeyValue()); String answer = json != null ? json.toJSONString() : requestHandler.handleThrowable(new Exception("Internal error while handling an exception")).toJSONString(); if (callback != null) { // Send a JSONP response sendResponse(pResp, "text/javascript", callback + "(" + answer + ");"); } else { sendResponse(pResp, getMimeType(pReq), answer); } } }