@Override public Channel writeJSON(Object value) { JSON.stringify(value, output.asOutputStream()); return this; }
@SuppressWarnings("unchecked") public static Map<String, Object> parseMap(String json) { return parse(json, Map.class); }
Map<String, Object> auth = JSON.parseMap(res.getBody());
private static void resetAppStateBeforeRestart() { App.boot.reset(); App.status = AppStatus.NOT_STARTED; App.dirty = false; App.packages = null; Groups.reset(); Conf.reset(); Env.reset(); Res.reset(); JSON.reset(); Beany.reset(); for (RapidoidModule mod : RapidoidModules.getAllAvailable()) { mod.restartApp(); } AppStarter.reset(); ClasspathScanner.reset(); invoked.clear(); Setups.reloadAll(); Setups.initDefaults(); Conf.reset(); // reset the config again }
public synchronized void init(HttpResponses responses, SessionStore sessionStore) { this.responses = responses; this.sessionStore = sessionStore; String cookiepack = cookie(HttpExchangeImpl.COOKIEPACK_COOKIE, null); if (!U.isEmpty(cookiepack) && !cookiepack.equals("null")) { String cpackStr = '"' + cookiepack + '"'; byte[] cpbytes = JSON.parseBytes(cpackStr); deserializeCookiepack(cpbytes); } }
public static byte[] parseBytes(String json) { return parse(json, byte[].class); }
@SuppressWarnings("unchecked") public static Object load(String json) { Map<String, Object> map = JSON.parseMap(json); String clsName = (String) map.get("_"); Class<Object> type = Cls.getClassIfExists(clsName); if (type == null) { return null; } Object ser = map.get("v"); if (ser instanceof Map) { Object value = Cls.newInstance(type); Map<String, Object> props = (Map<String, Object>) ser; Beany.update(value, props, false); return value; } return ser; }
private static void resetAppStateBeforeRestart() { App.path = null; App.boot = null; App.status = AppStatus.NOT_STARTED; App.dirty = false; Groups.reset(); Conf.reset(); Env.reset(); Res.reset(); Templates.reset(); JSON.reset(); Beany.reset(); AppStarter.reset(); AppBootstrap.reset(); ClasspathScanner.reset(); invoked.clear(); SetupUtil.reloadAll(); Conf.reset(); // reset the config again Setup.initDefaults(); // this changes the config Conf.reset(); // reset the config again }
@Override public void loadState() { if (isPostReq()) { String state = posted("__state", null); if (!U.isEmpty(state) && !state.equals("null")) { byte[] bytes = JSON.parseBytes('"' + state + '"'); deserializeLocals(bytes); } } }
private static NByteArrayEntity paramsBody(Map<String, Object> data, Map<String, List<Upload>> files) { data = U.safe(data); files = U.safe(files); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); for (Map.Entry<String, List<Upload>> entry : files.entrySet()) { for (Upload file : entry.getValue()) { builder = builder.addBinaryBody(entry.getKey(), file.content(), ContentType.DEFAULT_BINARY, file.filename()); } } for (Map.Entry<String, Object> entry : data.entrySet()) { String name = entry.getKey(); String value = JSON.stringify(entry.getValue()); builder = builder.addTextBody(name, value, ContentType.APPLICATION_JSON); } ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { builder.build().writeTo(stream); } catch (IOException e) { throw U.rte(e); } byte[] bytes = stream.toByteArray(); return new NByteArrayEntity(bytes, ContentType.MULTIPART_FORM_DATA); }
@SuppressWarnings("unchecked") private Map<String, ?> asMap() { if (target instanceof String) { return JSON.parse((String) target); } return as(Map.class); }
private void writeJsonBody(MaybeReq req, Buf out, Object value) { // Content-Length header out.append(CONTENT_LENGTH_UNKNOWN); int posConLen = out.size() - 1; out.append(CR_LF); closeHeaders(req, out); int posBefore = out.size(); JSON.stringify(value, out.asOutputStream()); int posAfter = out.size(); int contentLength = posAfter - posBefore; out.putNumAsText(posConLen, contentLength, false); }
public <T> T parse() { return JSON.parse(fetch()); }
protected void writeJsonBody(MaybeReq req, Channel ctx, Object value) { writeContentTypeHeader(ctx, MediaType.JSON); ReusableWritable out = Msc.locals().jsonRenderingStream(); JSON.stringify(value, out); HttpIO.INSTANCE.writeContentLengthHeader(ctx, out.size()); HttpIO.INSTANCE.closeHeaders(req, ctx.output()); ctx.write(out.array(), 0, out.size()); }
case JSON: try { return JSON.parse(data, targetType); } catch (Exception e) { if (firstException == null) {
private void writeJsonResponse(MaybeReq req, Resp resp, Channel ctx, boolean isKeepAlive, int code, MediaType contentType, Object result) { startResponse(resp, ctx, code, isKeepAlive, contentType); RapidoidThreadLocals locals = Msc.locals(); ReusableWritable out = locals.jsonRenderingStream(); // FIXME headers JSON.stringify(result, out); writeContentLengthHeader(ctx, out.size()); closeHeaders(req, ctx.output()); ctx.write(out.array(), 0, out.size()); }
@SuppressWarnings("unchecked") public void toUrlDecodedParams(Buf src, Map<String, Object> params, BufRanges contentTypes) { for (int i = 0; i < count; i++) { String key = keys[i].str(src.bytes()); String val = values[i].str(src.bytes()); boolean isJSON = isJSON(src, contentTypes, i); key = URIs.urlDecodeOrKeepOriginal(key); if (!isJSON) { val = URIs.urlDecodeOrKeepOriginal(val); if (key.endsWith("[]")) { key = Str.sub(key, 0, -2); List<String> list = (List<String>) params.get(key); if (list == null) { list = U.list(); params.put(key, list); } list.add(val); } else { params.put(key, val); } } else { params.put(key, JSON.parse(val)); } } }