javax.json.JsonException类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(210)

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

JsonException介绍

[英]JsonException indicates that some exception happened during JSON processing.
[中]JsonException表示在JSON处理过程中发生了一些异常。

代码示例

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

void flushBuffer() {
  try {
    if (len > 0) {
      writer.write(buf, 0, len);
      len = 0;
    }
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.GENERATOR_WRITE_IO_ERR(), ioe);
  }
}

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

@Override
public JsonStructure remove() {
  throw new JsonException(JsonMessages.NODEREF_VALUE_CANNOT_REMOVE());
}

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

private void missingMember(String op, String  member) {
  throw new JsonException(JsonMessages.PATCH_MEMBER_MISSING(op, member));
}

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

/**
 * Creates a JSON provider object. The provider is loaded using the
 * {@link ServiceLoader#load(Class)} method. If there are no available
 * service providers, this method returns the default service provider.
 * Users are recommended to cache the result of this method.
 *
 * @see ServiceLoader
 * @return a JSON provider
 */
public static JsonProvider provider() {
  ServiceLoader<JsonProvider> loader = ServiceLoader.load(JsonProvider.class);
  Iterator<JsonProvider> it = loader.iterator();
  if (it.hasNext()) {
    return it.next();
  }
  try {
    Class<?> clazz = Class.forName(DEFAULT_PROVIDER);
    return (JsonProvider) clazz.newInstance();
  } catch (ClassNotFoundException x) {
    throw new JsonException(
        "Provider " + DEFAULT_PROVIDER + " not found", x);
  } catch (Exception x) {
    throw new JsonException(
        "Provider " + DEFAULT_PROVIDER + " could not be instantiated: " + x,
        x);
  }
}

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

@Override
public void flush() {
  flushBuffer();
  try {
    writer.flush();
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.GENERATOR_FLUSH_IO_ERR(), ioe);
  }
}

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

throw new JsonException(JsonMessages.INTERNAL_ERROR());
throw new JsonException(JsonMessages.INTERNAL_ERROR());

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

/**
   * Computes the array index
   * @param token the input string token
   * @return the array index. -1 if the token is "-"
   * @throws JsonException if the string token is not in correct format
   */
  static private int getIndex(String token) {
    if (token == null || token.length() == 0) {
      throw new JsonException(JsonMessages.POINTER_ARRAY_INDEX_ERR(token));
    }
    if (token.equals("-")) {
      return -1;
    }
    if (token.equals("0")) {
      return 0;
    }
    if (token.charAt(0) == '+' || token.charAt(0) == '-') {
      throw new JsonException(JsonMessages.POINTER_ARRAY_INDEX_ERR(token));
    }
    try {
      return Integer.parseInt(token);
    } catch (NumberFormatException ex) {
      throw new JsonException(JsonMessages.POINTER_ARRAY_INDEX_ILLEGAL(token), ex);
    }
  }
}

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

/**
 * Constructs and initializes a JsonPointerImpl.
 * @param jsonPointer the JSON Pointer string
 * @throws NullPointerException if {@code jsonPointer} is {@code null}
 * @throws JsonException if {@code jsonPointer} is not a valid JSON Pointer
 */
public JsonPointerImpl(String jsonPointer) {
  this.jsonPointer = jsonPointer;
  tokens = jsonPointer.split("/", -1);  // keep the trailing blanks
  if (! "".equals(tokens[0])) {
    throw new JsonException(JsonMessages.POINTER_FORMAT_INVALID());
  }
  for (int i = 1; i < tokens.length; i++) {
    String token = tokens[i];
    StringBuilder reftoken = new StringBuilder();
    for (int j = 0; j < token.length(); j++) {
      char ch = token.charAt(j);
      if (ch == '~' && j < token.length() - 1) {
        char ch1 = token.charAt(j+1);
        if (ch1 == '0') {
          ch = '~'; j++;
        } else if (ch1 == '1') {
          ch = '/'; j++;
        }
      }
      reftoken.append(ch);
    }
    tokens[i] = reftoken.toString();
  }
}

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

@Override
public void close() {
  try {
    tokenizer.close();
  } catch (IOException e) {
    throw new JsonException(JsonMessages.PARSER_TOKENIZER_CLOSE_IO(), e);
  }
}

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

@Override
public JsonStructure add(JsonValue value) {
  switch (value.getValueType() ) {
    case OBJECT:
    case ARRAY:
      this.root = (JsonStructure) value;
      break;
    default:
      throw new JsonException(JsonMessages.NODEREF_VALUE_ADD_ERR());
  }
  return root;
}

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

/**
   * Returns the enum constant with the specified name.
   *
   * @param operationName {@code operationName} to convert to the enum constant.
   * @return the enum constant for given {@code operationName}
   * @throws JsonException if given {@code operationName} is not recognized
   */
  public static Operation fromOperationName(String operationName) {
    for (Operation op : values()) {
      if (op.operationName().equalsIgnoreCase(operationName)) {
        return op;
      }
    }
    throw new JsonException("Illegal value for the operationName of the JSON patch operation: " + operationName);
  }
}

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

buf[3] = (byte)b4;
} catch (IOException ioe) {
  throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_IOERR(), ioe);

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

private int peek() {
  try {
    if (readBegin == readEnd) {     // need to fill the buffer
      int len = fillBuf();
      if (len == -1) {
        return -1;
      }
      assert len != 0;
      readBegin = storeEnd;
      readEnd = readBegin+len;
    }
    return buf[readBegin];
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe);
  }
}

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

private int read() {
  try {
    if (readBegin == readEnd) {     // need to fill the buffer
      int len = fillBuf();
      if (len == -1) {
        return -1;
      }
      assert len != 0;
      readBegin = storeEnd;
      readEnd = readBegin+len;
    }
    return buf[readBegin++];
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe);
  }
}

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

static Scope createScope(JsonValue value) {
    if (value instanceof JsonArray) {
      return new ArrayScope((JsonArray)value);
    } else if (value instanceof JsonObject) {
      return new ObjectScope((JsonObject)value);
    }
    throw new JsonException(JsonMessages.PARSER_SCOPE_ERR(value));
  }
}

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

@Override
  public JsonObject replace(JsonValue value) {
    if (!contains()) {
      throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key));
    }
    return add(value);
  }
}

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

@Override
public JsonObject remove() {
  if (!contains()) {
    throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key));
  }
  return Json.createObjectBuilder(object).remove(key).build();
}

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

@Override
public JsonValue get() {
  if (!contains()) {
    throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key));
  }
  return object.get(key);
}

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

String key = classifier.apply(value);
if (key == null) {
  throw new JsonException("element cannot be mapped to a null key");

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

private Charset detectEncoding() {
  fillBuf();
  if (bufLen < 2) {
    throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_FAILED());
  } else if (bufLen == 4) {

相关文章