io.vertx.core.json.EncodeException Java Examples

The following examples show how to use io.vertx.core.json.EncodeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionTransmitter.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
public void send() {
  final Optional<JsonRpcRequest> request = createSignedTransactionBody();

  if (request.isEmpty()) {
    return;
  }

  try {
    sendTransaction(Json.encodeToBuffer(request.get()));
  } catch (final IllegalArgumentException | EncodeException e) {
    LOG.debug("JSON Serialization failed for: {}", request, e);
    routingContext.fail(BAD_REQUEST.code(), new JsonRpcException(INTERNAL_ERROR));
  }
}
 
Example #2
Source File: JDBCSpaceConfigClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
@Override
protected void storeSpace(Marker marker, Space space, Handler<AsyncResult<Space>> handler) {
  SQLQuery query = null;
  try {
    query = new SQLQuery(String.format(
        "INSERT INTO %s(id, owner, cid, config) VALUES (?, ?, ?, cast(? as JSONB)) ON CONFLICT (id) DO UPDATE SET owner = excluded.owner, cid = excluded.cid, config = excluded.config",
        SPACE_TABLE), space.getId(), space.getOwner(), space.getCid(),
        XyzSerializable.STATIC_MAPPER.get().writeValueAsString(space));
    updateWithParams(space, query, handler);
  } catch (JsonProcessingException e) {
    handler.handle(Future.failedFuture(new EncodeException("Failed to encode as JSON: " + e.getMessage(), e)));
  }
}
 
Example #3
Source File: ParamCheckUtil.java    From VX-API-Gateway with MIT License 5 votes vote down vote up
/**
 * 检查是否为json格式
 * 
 * @param obj
 * @return
 */
public static boolean isJosn(Object obj) {
	try {
		Json.encode(obj);
		return true;
	} catch (EncodeException e) {
		return false;
	}
}
 
Example #4
Source File: JsonCodec.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public static String encode(String[] messages) throws EncodeException {
  StringWriter sw = new StringWriter();
  try (JsonGenerator gen = factory.createGenerator(sw)) {
    gen.writeStartArray();
    boolean first = true;
    for (String message : messages) {
      if (first) {
        first = false;
      } else {
        gen.writeRaw(',');
      }
      gen.writeRaw('"');
      for (char c : message.toCharArray()) {
        if (c >= 0x80) writeUnicodeEscape(gen, c); // use generic escaping for all non US-ASCII characters
        else {
          // use escape table for first 128 characters
          int code = (c < ESCAPE_CODES.length ? ESCAPE_CODES[c] : 0);
          if (code == 0) gen.writeRaw(c); // no escaping
          else if (code == -1) writeUnicodeEscape(gen, c); // generic escaping
          else writeShortEscape(gen, (char) code); // short escaping (\n \t ...)
        }
      }
      gen.writeRaw('"');
    }
    gen.writeEndArray();
    gen.close();
    return sw.toString();
  } catch (Exception e) {
    throw new EncodeException("Failed to encode as JSON", e);
  }
}