本文整理汇总了Java中io.vertx.core.json.Json.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Json.encode方法的具体用法?Java Json.encode怎么用?Java Json.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.json.Json
的用法示例。
在下文中一共展示了Json.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void insert(T dd, Handler<ExtendedAsyncResult<Void>> fut) {
PostgresQuery q = pg.getQuery();
final String sql = "INSERT INTO " + table + "(" + jsonColumn + ") VALUES (?::JSONB)";
String s = Json.encode(dd);
JsonObject doc = new JsonObject(s);
JsonArray jsa = new JsonArray();
jsa.add(doc.encode());
q.queryWithParams(sql, jsa, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
q.close();
fut.handle(new Success<>());
}
});
}
示例2: update
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void update(T md, Handler<ExtendedAsyncResult<Void>> fut) {
PostgresQuery q = pg.getQuery();
String sql = "INSERT INTO " + table + "(" + jsonColumn + ") VALUES (?::JSONB)"
+ " ON CONFLICT ((" + idIndex + ")) DO UPDATE SET " + jsonColumn + "= ?::JSONB";
String s = Json.encode(md);
JsonObject doc = new JsonObject(s);
JsonArray jsa = new JsonArray();
jsa.add(doc.encode());
jsa.add(doc.encode());
q.updateWithParams(sql, jsa, res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
q.close();
fut.handle(new Success<>());
}
});
}
示例3: encodeToWire
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Override
public void encodeToWire(Buffer buffer, Book book) {
// Easiest ways is using JSON object
String json = Json.encode(book);
// Length of JSON: is NOT characters count
int length = json.getBytes().length;
// Write data into given buffer
buffer.appendInt(length);
buffer.appendString(json);
}
示例4: out
import io.vertx.core.json.Json; //导入方法依赖的package包/类
private static String out(Object output) {
if (output == null) {
return null;
} else if (output instanceof String) {
return (String) output;
} else {
return Json.encode(output);
}
}
示例5: getValue
import io.vertx.core.json.Json; //导入方法依赖的package包/类
/**
* Return the object o set by setValue(o) encoded as a JSON string. Return null if o is null
* or if o is neither a JsonObject nor a String nor a primitive type.
* @return the JSON string
*/
public String getValue() {
if (value == null) {
return null;
}
if (value instanceof JsonObject) {
return ((JsonObject) value).encode();
}
if (value instanceof String || value.getClass().isPrimitive() || Primitives.isWrapperType(value.getClass())) {
return Json.encode(value);
}
return null;
}
示例6: sendMessagge
import io.vertx.core.json.Json; //导入方法依赖的package包/类
/**
* send a gremlin script message to event bus.
*
* @param message {@linkplain GremlinScriptMessage}
* @param replyHandler the handler for the replied result message.
*/
public void sendMessagge(GremlinScriptMessage message, Handler<AsyncResult<Message<String>>> replyHandler) {
if (canBeUse) {
String encodeMessage = Json.encode(message);
eventBus.send(eventBusAddress, encodeMessage, replyHandler);
}
}
示例7: moduleTokens
import io.vertx.core.json.Json; //导入方法依赖的package包/类
/**
* Fake some module permissions.
* Generates silly tokens with the module name as the tenant, and a list
* of permissions as the user. These are still valid tokens, although it is
* not possible to extract the user or tenant from them.
*/
private String moduleTokens(RoutingContext ctx) {
String modPermJson = ctx.request().getHeader(XOkapiHeaders.MODULE_PERMISSIONS);
logger.debug("test-auth: moduleTokens: trying to decode '" + modPermJson + "'");
HashMap<String, String> tokens = new HashMap<>();
if (modPermJson != null && !modPermJson.isEmpty()) {
JsonObject jo = new JsonObject(modPermJson);
StringBuilder permstr = new StringBuilder();
for (String mod : jo.fieldNames()) {
JsonArray ja = jo.getJsonArray(mod);
for (int i = 0; i < ja.size(); i++) {
String p = ja.getString(i);
if (permstr.length() > 0) {
permstr.append(",");
}
permstr.append(p);
}
tokens.put(mod, token(mod, permstr.toString()));
}
}
if (!tokens.isEmpty()) { // return also a 'clean' token
tokens.put("_", ctx.request().getHeader(XOkapiHeaders.TOKEN));
}
String alltokens = Json.encode(tokens);
logger.debug("test-auth: module tokens for " + modPermJson + " : " + alltokens);
return alltokens;
}
示例8: transform
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Override
protected String transform(Object data) {
return Json.encode(simpleResponse(data));
}
示例9: createGraph
import io.vertx.core.json.Json; //导入方法依赖的package包/类
private String createGraph() {
GremlinMessage gremlinMessage = new GremlinMessage();
gremlinMessage.setGremlinScript("graph = TinkerFactory.createModern()");
return Json.encode(gremlinMessage);
}
示例10: createG
import io.vertx.core.json.Json; //导入方法依赖的package包/类
private String createG() {
GremlinMessage gremlinMessage = new GremlinMessage();
gremlinMessage.setGremlinScript("g = graph.traversal(standard())");
return Json.encode(gremlinMessage);
}
示例11: getRootLogLevel
import io.vertx.core.json.Json; //导入方法依赖的package包/类
private void getRootLogLevel(Handler<ExtendedAsyncResult<String>> fut) {
String lev = logHelper.getRootLogLevel();
LogHelper.LogLevelInfo li = new LogHelper.LogLevelInfo(lev);
String rj = Json.encode(li);
fut.handle(new Success<>(rj));
}
示例12: authHeaders
import io.vertx.core.json.Json; //导入方法依赖的package包/类
/**
* Get the auth bits from the module list into X-Okapi-Permissions-Required
* and X-Okapi-Permissions-Desired headers. Also X-Okapi-Module-Permissions
* for each module that has such. At the same time, sets the authToken to
* default for each module. Some of these will be overwritten once the auth
* module returns with dedicated tokens, but by default we use the one given
* to us by the client.
*
*/
private void authHeaders(List<ModuleInstance> modlist,
MultiMap requestHeaders, String defaultToken, ProxyContext pc) {
// Sanitize important headers from the incoming request
requestHeaders.remove(XOkapiHeaders.PERMISSIONS_REQUIRED);
requestHeaders.remove(XOkapiHeaders.PERMISSIONS_DESIRED);
requestHeaders.remove(XOkapiHeaders.MODULE_PERMISSIONS);
requestHeaders.remove(XOkapiHeaders.EXTRA_PERMISSIONS);
requestHeaders.remove(XOkapiHeaders.MODULE_TOKENS);
Set<String> req = new HashSet<>();
Set<String> want = new HashSet<>();
Set<String> extraperms = new HashSet<>();
Map<String, String[]> modperms = new HashMap<>(modlist.size());
for (ModuleInstance mod : modlist) {
RoutingEntry re = mod.getRoutingEntry();
String[] reqp = re.getPermissionsRequired();
if (reqp != null) {
req.addAll(Arrays.asList(reqp));
}
String[] wap = re.getPermissionsDesired();
if (wap != null) {
want.addAll(Arrays.asList(wap));
}
String[] modp = re.getModulePermissions();
if (modp != null) {
if (re.getProxyType() == ProxyType.REDIRECT) {
extraperms.addAll(Arrays.asList(modp));
} else {
modperms.put(mod.getModuleDescriptor().getId(), modp);
}
}
mod.setAuthToken(defaultToken);
} // mod loop
if (!req.isEmpty()) {
pc.debug("authHeaders: " + XOkapiHeaders.PERMISSIONS_REQUIRED + " " + String.join(",", req));
requestHeaders.add(XOkapiHeaders.PERMISSIONS_REQUIRED, String.join(",", req));
}
if (!want.isEmpty()) {
pc.debug("authHeaders: " + XOkapiHeaders.PERMISSIONS_DESIRED + " " + String.join(",", want));
requestHeaders.add(XOkapiHeaders.PERMISSIONS_DESIRED, String.join(",", want));
}
// Add the X-Okapi-Module-Permissions even if empty. That causes auth to return
// an empty X-Okapi-Module-Token, which will tell us that we have done the mod
// perms, and no other module should be allowed to do the same.
String mpj = Json.encode(modperms);
pc.debug("authHeaders: " + XOkapiHeaders.MODULE_PERMISSIONS + " " + mpj);
requestHeaders.add(XOkapiHeaders.MODULE_PERMISSIONS, mpj);
if (!extraperms.isEmpty()) {
String epj = Json.encode(extraperms);
pc.debug("authHeaders: " + XOkapiHeaders.EXTRA_PERMISSIONS + " " + epj);
requestHeaders.add(XOkapiHeaders.EXTRA_PERMISSIONS, epj);
}
}
示例13: encodeTenant
import io.vertx.core.json.Json; //导入方法依赖的package包/类
private JsonObject encodeTenant(Tenant t, String id) {
JsonObject j = new JsonObject(Json.encode(t));
util.encode(j, id);
return j;
}
示例14: add
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void add(String k, String k2, T value, Handler<ExtendedAsyncResult<Void>> fut) {
String json = Json.encode(value);
addOrReplace(false, k, k2, json, fut);
}
示例15: add
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void add(String k, T value, Handler<ExtendedAsyncResult<Void>> fut) {
String json = Json.encode(value);
addOrReplace(false, k, null, json, fut);
}