io.vertx.core.json.DecodeException类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(504)

本文整理了Java中io.vertx.core.json.DecodeException类的一些代码示例,展示了DecodeException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DecodeException类的具体详情如下:
包路径:io.vertx.core.json.DecodeException
类名称:DecodeException

DecodeException介绍

[英]Instances of this Exception are thrown if failed to decode a JSON string, because of invalid JSON.
[中]如果由于JSON无效而未能解码JSON字符串,则会引发此异常的实例。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Decode a given JSON string to a POJO of the given type.
 * @param str the JSON string.
 * @param type the type to map to.
 * @param <T> the generic type.
 * @return an instance of T
 * @throws DecodeException when there is a parsing or invalid mapping.
 */
public static <T> T decodeValue(String str, TypeReference<T> type) throws DecodeException {
 try {
  return mapper.readValue(str, type);
 } catch (Exception e) {
  throw new DecodeException("Failed to decode: " + e.getMessage(), e);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

protected JsonObject getJsonFromFileOrString(String jsonFileOrString, String argName) {
 JsonObject conf;
 if (jsonFileOrString != null) {
  try (Scanner scanner = new Scanner(new File(jsonFileOrString), "UTF-8").useDelimiter("\\A")) {
   String sconf = scanner.next();
   try {
    conf = new JsonObject(sconf);
   } catch (DecodeException e) {
    log.error("Configuration file " + sconf + " does not contain a valid JSON object");
    return null;
   }
  } catch (FileNotFoundException e) {
   try {
    conf = new JsonObject(jsonFileOrString);
   } catch (DecodeException e2) {
    // The configuration is not printed for security purpose, it can contain sensitive data.
    log.error("The -" + argName + " argument does not point to an existing file or is not a valid JSON object");
    e2.printStackTrace();
    return null;
   }
  }
 } else {
  conf = null;
 }
 return conf;
}

代码示例来源:origin: folio-org/okapi

private JsonObject getPayload() {
 String encodedJson;
 try {
  encodedJson = this.token.split("\\.")[1];
 } catch (ArrayIndexOutOfBoundsException e) {
  throw new IllegalArgumentException(e.getMessage());
 }
 String decodedJson = new String(Base64.getDecoder().decode(encodedJson));
 JsonObject j;
 try {
  j = new JsonObject(decodedJson);
 } catch (DecodeException e) {
  throw new IllegalArgumentException(e.getMessage());
 }
 return j;
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-routing

@Override
public void resourceChanged(String resourceUri, String resource) {
  if (configResourceUri != null && configResourceUri.equals(resourceUri)) {
    log.info("Got notified about configuration resource update for " + resourceUri + " with new data: " + resource);
    try {
      JsonObject obj = new JsonObject(resource);
      Integer requestHopsLimitValue = obj.getInteger(REQUEST_HOPS_LIMIT_PROPERTY);
      if (requestHopsLimitValue != null) {
        log.info("Got value '" + requestHopsLimitValue + "' for property '"+ REQUEST_HOPS_LIMIT_PROPERTY +"'. Request hop validation is now activated");
        requestHopsLimit = requestHopsLimitValue;
      } else {
        log.warn("No value for property '"+ REQUEST_HOPS_LIMIT_PROPERTY +"' found. Request hop validation will not be activated");
        requestHopsLimit = null;
      }
    } catch (DecodeException ex) {
      log.warn("Unable to decode configuration resource for " + resourceUri + " with data: " + resource + " Reason: " + ex.getMessage());
      requestHopsLimit = null;
    }
  }
}

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Decode a given JSON string to a POJO of the given class type.
 * @param str the JSON string.
 * @param clazz the class to map to.
 * @param <T> the generic type.
 * @return an instance of T
 * @throws DecodeException when there is a parsing or invalid mapping.
 */
public static <T> T decodeValue(String str, Class<T> clazz) throws DecodeException {
 try {
  return mapper.readValue(str, clazz);
 } catch (Exception e) {
  throw new DecodeException("Failed to decode: " + e.getMessage());
 }
}

代码示例来源:origin: georocket/georocket

System.exit(1);
} catch (DecodeException e) {
 System.err.println("Invalid config file: " + e.getMessage());
 System.exit(1);

代码示例来源:origin: io.vertx/vertx-core

protected JsonObject getJsonFromFileOrString(String jsonFileOrString, String argName) {
 JsonObject conf;
 if (jsonFileOrString != null) {
  try (Scanner scanner = new Scanner(new File(jsonFileOrString), "UTF-8").useDelimiter("\\A")) {
   String sconf = scanner.next();
   try {
    conf = new JsonObject(sconf);
   } catch (DecodeException e) {
    log.error("Configuration file " + sconf + " does not contain a valid JSON object");
    return null;
   }
  } catch (FileNotFoundException e) {
   try {
    conf = new JsonObject(jsonFileOrString);
   } catch (DecodeException e2) {
    // The configuration is not printed for security purpose, it can contain sensitive data.
    log.error("The -" + argName + " argument does not point to an existing file or is not a valid JSON object");
    e2.printStackTrace();
    return null;
   }
  }
 } else {
  conf = null;
 }
 return conf;
}

代码示例来源:origin: eclipse-vertx/vert.x

<T> T convert(Class<T> type) {
  try {
   return Json.mapper.readValue(buffer.asParser(), type);
  } catch (Exception e) {
   throw new DecodeException(e.getMessage());
  }
 }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-hook

private boolean isListenerJsonInvalid(HttpServerRequest request, Buffer hookData) {
  if (isHookJsonInvalid(request, hookData)) {
    // No further checks required. hook definitively is invalid.
    return true;
  }
  final JsonObject hook;
  try {
    // Badly we need to parse that JSON one more time.
    hook = new JsonObject(hookData);
  } catch (DecodeException e) {
    log.error("Cannot decode JSON", e);
    badRequest(request, "Cannot decode JSON", e.getMessage());
    return true;
  }
  final JsonArray methods = hook.getJsonArray("methods");
  if (methods != null) {
    for (Object method : methods) {
      if (!QueueProcessor.httpMethodIsQueueable(HttpMethod.valueOf((String) method))) {
        final String msg = "Listener registration request tries to hook for not allowed '" + method + "' method.";
        log.error(msg);
        badRequest(request, "Bad Request", msg + "\n");
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public <T> T mapTo(Class<T> type) {
 if (buffer != null) {
  try {
   return Json.mapper.readValue(buffer.asParser(), type);
  } catch (Exception e) {
   throw new DecodeException(e.getMessage());
  }
 } else {
  return Json.decodeValue(String.valueOf(value), type);
 }
}

代码示例来源:origin: org.swisspush/gateleen-core

} catch (DecodeException e) {
  request.response().setStatusCode(BAD_REQUEST);
  request.response().end(e.getMessage());
  return;

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public <T> T mapTo(TypeReference<T> type) {
 if (buffer != null) {
  try {
   return Json.mapper.readValue(buffer.asParser(), type);
  } catch (Exception e) {
   throw new DecodeException(e.getMessage());
  }
 } else {
  return Json.decodeValue(String.valueOf(value), type);
 }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-hook

} catch (DecodeException e) {
  log.error("Cannot decode JSON", e);
  badRequest(request, "Cannot decode JSON", e.getMessage());
  return;

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Decode a given JSON buffer to a POJO of the given class type.
 * @param buf the JSON buffer.
 * @param clazz the class to map to.
 * @param <T> the generic type.
 * @return an instance of T
 * @throws DecodeException when there is a parsing or invalid mapping.
 */
public static <T> T decodeValue(Buffer buf, Class<T> clazz) throws DecodeException {
 try {
  return mapper.readValue((InputStream) new ByteBufInputStream(buf.getByteBuf()), clazz);
 } catch (Exception e) {
  throw new DecodeException("Failed to decode:" + e.getMessage(), e);
 }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-hook

hook = new JsonObject(hookData.toString());
} catch (DecodeException e) {
  badRequest(request, "Cannot decode JSON", e.getMessage());
  return;

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Decode a given JSON buffer to a POJO of the given class type.
 * @param buf the JSON buffer.
 * @param type the type to map to.
 * @param <T> the generic type.
 * @return an instance of T
 * @throws DecodeException when there is a parsing or invalid mapping.
 */
public static <T> T decodeValue(Buffer buf, TypeReference<T> type) throws DecodeException {
 try {
  return mapper.readValue(new ByteBufInputStream(buf.getByteBuf()), type);
 } catch (Exception e) {
  throw new DecodeException("Failed to decode:" + e.getMessage(), e);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public void handle(Buffer event) {
 byte[] bytes = event.getBytes();
 try {
  parser.feedInput(bytes, 0, bytes.length);
 } catch (IOException e) {
  if (exceptionHandler != null) {
   exceptionHandler.handle(e);
   return;
  } else {
   throw new DecodeException(e.getMessage());
  }
 }
 checkPending();
}

代码示例来源:origin: eclipse-vertx/vert.x

exceptionHandler.handle(e);
} else {
 throw new DecodeException(e.getMessage());

代码示例来源:origin: vert-x3/vertx-web

public static <T> T decodeValue(String str, Class<T> clazz) throws DecodeException {
  try {
   return mapper.readValue(str, clazz);
  }
  catch (Exception e) {
   throw new DecodeException("Failed to decode");
  }
 }
}

代码示例来源:origin: io.vertx/vertx-core

/**
 * Decode a given JSON string to a POJO of the given type.
 * @param str the JSON string.
 * @param type the type to map to.
 * @param <T> the generic type.
 * @return an instance of T
 * @throws DecodeException when there is a parsing or invalid mapping.
 */
public static <T> T decodeValue(String str, TypeReference<T> type) throws DecodeException {
 try {
  return mapper.readValue(str, type);
 } catch (Exception e) {
  throw new DecodeException("Failed to decode: " + e.getMessage(), e);
 }
}

相关文章

微信公众号

最新文章

更多