當前位置: 首頁>>代碼示例>>Java>>正文


Java Json.encode方法代碼示例

本文整理匯總了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<>());
    }
  });
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:17,代碼來源:PostgresTable.java

示例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<>());
    }
  });
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:19,代碼來源:PostgresTable.java

示例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);
}
 
開發者ID:ANierbeck,項目名稱:Karaf-Vertx,代碼行數:13,代碼來源:BookEncoder.java

示例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);
	}
}
 
開發者ID:nielsbaloe,項目名稱:vertxui,代碼行數:10,代碼來源:Pojofy.java

示例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;
}
 
開發者ID:folio-org,項目名稱:raml-module-builder,代碼行數:18,代碼來源:UpdateSection.java

示例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);
    }
}
 
開發者ID:openmg,項目名稱:vertx-gremlin,代碼行數:13,代碼來源:VertexGremlinClient.java

示例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;
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:33,代碼來源:Auth.java

示例8: transform

import io.vertx.core.json.Json; //導入方法依賴的package包/類
@Override
protected String transform(Object data) {
	
	return Json.encode(simpleResponse(data));
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:6,代碼來源:RestAPIHandler.java

示例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);
}
 
開發者ID:openmg,項目名稱:vertx-gremlin,代碼行數:6,代碼來源:GremlinClient.java

示例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);
}
 
開發者ID:openmg,項目名稱:vertx-gremlin,代碼行數:6,代碼來源:GremlinClient.java

示例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));
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:7,代碼來源:InternalModule.java

示例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);
  }
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:62,代碼來源:ProxyService.java

示例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;
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:6,代碼來源:TenantStoreMongo.java

示例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);
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:5,代碼來源:LockedTypedMap2.java

示例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);
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:5,代碼來源:LockedTypedMap1.java


注:本文中的io.vertx.core.json.Json.encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。