本文整理了Java中org.rapidoid.data.JSON
类的一些代码示例,展示了JSON
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON
类的具体详情如下:
包路径:org.rapidoid.data.JSON
类名称:JSON
暂无
代码示例来源:origin: rapidoid/rapidoid
@Override
public Channel writeJSON(Object value) {
JSON.stringify(value, output.asOutputStream());
return this;
}
代码示例来源:origin: rapidoid/rapidoid
public static void warmUp() {
Msc.thread(() -> {
JSON.stringify(123);
JSON.parse("{}", Map.class);
});
}
代码示例来源:origin: rapidoid/rapidoid
public static Map<String, Object> deepCopyOf(Map<String, Object> map) {
return JSON.parseMap(JSON.stringify(map)); // FIXME proper implementation
}
代码示例来源:origin: rapidoid/rapidoid
@SuppressWarnings("unchecked")
public static Map<String, Object> parseMap(String json) {
return parse(json, Map.class);
}
代码示例来源:origin: rapidoid/rapidoid
Map<String, Object> auth = JSON.parseMap(res.getBody());
代码示例来源:origin: rapidoid/rapidoid
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
}
代码示例来源:origin: org.rapidoid/rapidoid-http
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);
}
}
代码示例来源:origin: rapidoid/rapidoid
public static byte[] parseBytes(String json) {
return parse(json, byte[].class);
}
代码示例来源:origin: org.rapidoid/rapidoid-beany
@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;
}
代码示例来源:origin: org.rapidoid/rapidoid-http-server
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
}
代码示例来源:origin: org.rapidoid/rapidoid-http
@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);
}
}
}
代码示例来源:origin: rapidoid/rapidoid
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);
}
代码示例来源:origin: org.rapidoid/rapidoid-jackson
public static void warmup() {
JSON.stringify(123);
JSON.parse("{}", Map.class);
}
代码示例来源:origin: rapidoid/rapidoid
@SuppressWarnings("unchecked")
private Map<String, ?> asMap() {
if (target instanceof String) {
return JSON.parse((String) target);
}
return as(Map.class);
}
代码示例来源:origin: rapidoid/rapidoid
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);
}
代码示例来源:origin: rapidoid/rapidoid
public <T> T parse() {
return JSON.parse(fetch());
}
代码示例来源:origin: rapidoid/rapidoid
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());
}
代码示例来源:origin: rapidoid/rapidoid
case JSON:
try {
return JSON.parse(data, targetType);
} catch (Exception e) {
if (firstException == null) {
代码示例来源:origin: rapidoid/rapidoid
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());
}
代码示例来源:origin: rapidoid/rapidoid
@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));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!