com.linecorp.centraldogma.internal.Jackson.treeToValue()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(150)

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

Jackson.treeToValue介绍

暂无

代码示例

代码示例来源:origin: line/centraldogma

/**
 * Returns a properties object which is converted to {@code T}.
 */
@Nullable
public <T> T properties(Class<T> clazz) throws JsonProcessingException {
  return properties != null ? Jackson.treeToValue(properties, clazz) : null;
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

/**
 * Returns a properties object which is converted to {@code T}.
 */
@Nullable
public <T> T properties(Class<T> clazz) throws JsonProcessingException {
  return properties != null ? Jackson.treeToValue(properties, clazz) : null;
}

代码示例来源:origin: line/centraldogma

/**
   * Returns a {@link ProjectRole} matched with the specified {@link JsonNode}.
   *
   * @throws IllegalArgumentException if there is no matched {@link ProjectRole}.
   */
  public static ProjectRole of(JsonNode node) {
    requireNonNull(node, "node");
    try {
      return Jackson.treeToValue(node, ProjectRole.class);
    } catch (JsonProcessingException e) {
      throw new IllegalArgumentException(e);
    }
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded

/**
   * Returns a {@link ProjectRole} matched with the specified {@link JsonNode}.
   *
   * @throws IllegalArgumentException if there is no matched {@link ProjectRole}.
   */
  public static ProjectRole of(JsonNode node) {
    requireNonNull(node, "node");
    try {
      return Jackson.treeToValue(node, ProjectRole.class);
    } catch (JsonProcessingException e) {
      throw new IllegalArgumentException(e);
    }
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

/**
   * Returns a {@link ProjectRole} matched with the specified {@link JsonNode}.
   *
   * @throws IllegalArgumentException if there is no matched {@link ProjectRole}.
   */
  public static ProjectRole of(JsonNode node) {
    requireNonNull(node, "node");
    try {
      return Jackson.treeToValue(node, ProjectRole.class);
    } catch (JsonProcessingException e) {
      throw new IllegalArgumentException(e);
    }
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

/**
 * Static factory method to build a JSON Patch out of a JSON representation.
 *
 * @param node the JSON representation of the generated JSON Patch
 * @return a JSON Patch
 * @throws IOException input is not a valid JSON patch
 * @throws NullPointerException input is null
 */
public static JsonPatch fromJson(final JsonNode node) throws IOException {
  requireNonNull(node, "node");
  try {
    return Jackson.treeToValue(node, JsonPatch.class);
  } catch (JsonMappingException e) {
    throw new JsonPatchException("invalid JSON patch", e);
  }
}

代码示例来源:origin: line/centraldogma

/**
 * Static factory method to build a JSON Patch out of a JSON representation.
 *
 * @param node the JSON representation of the generated JSON Patch
 * @return a JSON Patch
 * @throws IOException input is not a valid JSON patch
 * @throws NullPointerException input is null
 */
public static JsonPatch fromJson(final JsonNode node) throws IOException {
  requireNonNull(node, "node");
  try {
    return Jackson.treeToValue(node, JsonPatch.class);
  } catch (JsonMappingException e) {
    throw new JsonPatchException("invalid JSON patch", e);
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

/**
 * Static factory method to build a JSON Patch out of a JSON representation.
 *
 * @param node the JSON representation of the generated JSON Patch
 * @return a JSON Patch
 * @throws IOException input is not a valid JSON patch
 * @throws NullPointerException input is null
 */
public static JsonPatch fromJson(final JsonNode node) throws IOException {
  requireNonNull(node, "node");
  try {
    return Jackson.treeToValue(node, JsonPatch.class);
  } catch (JsonMappingException e) {
    throw new JsonPatchException("invalid JSON patch", e);
  }
}

代码示例来源:origin: line/centraldogma

@SuppressWarnings("unchecked")
  static <T> T convertWithJackson(Entry<?> entry, Class<T> clazz) {
    requireNonNull(entry, "entry");
    requireNonNull(clazz, "clazz");
    try {
      return Jackson.treeToValue(((Entry<JsonNode>) entry).content(), clazz);
    } catch (Throwable cause) {
      return Exceptions.throwUnsafely(cause);
    }
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded

@SuppressWarnings("unchecked")
  static <T> T convertWithJackson(Entry<?> entry, Class<T> clazz) {
    requireNonNull(entry, "entry");
    requireNonNull(clazz, "clazz");
    try {
      return Jackson.treeToValue(((Entry<JsonNode>) entry).content(), clazz);
    } catch (Throwable cause) {
      return Exceptions.throwUnsafely(cause);
    }
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

@SuppressWarnings("unchecked")
  static <T> T convertWithJackson(Entry<?> entry, Class<T> clazz) {
    requireNonNull(entry, "entry");
    requireNonNull(clazz, "clazz");
    try {
      return Jackson.treeToValue(((Entry<JsonNode>) entry).content(), clazz);
    } catch (Throwable cause) {
      return Exceptions.throwUnsafely(cause);
    }
  }
}

代码示例来源:origin: line/centraldogma

private static List<MirrorCredential> loadCredentials(Map<String, Entry<?>> entries) throws Exception {
  final Entry<?> e = entries.get(PATH_CREDENTIALS);
  if (e == null) {
    return Collections.emptyList();
  }
  final JsonNode credentialsJson = (JsonNode) e.content();
  if (!credentialsJson.isArray()) {
    throw new RepositoryMetadataException(
        PATH_CREDENTIALS + " must be an array: " + credentialsJson.getNodeType());
  }
  if (credentialsJson.size() == 0) {
    return Collections.emptyList();
  }
  final ImmutableList.Builder<MirrorCredential> builder = ImmutableList.builder();
  for (JsonNode c : credentialsJson) {
    final MirrorCredential credential = Jackson.treeToValue(c, MirrorCredential.class);
    if (credential == null) {
      throw new RepositoryMetadataException(PATH_CREDENTIALS + " contains null.");
    }
    builder.add(credential);
  }
  return builder.build();
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded

@Nullable
private static <T> T deserializeResult(
    JsonNode result, Command<T> command) throws JsonProcessingException {
  requireNonNull(command, "command");
  // Convert null node to the real null.
  if (result != null && result.isNull()) {
    result = null;
  }
  final Class<T> resultType = Util.unsafeCast(command.type().resultType());
  if (resultType == Void.class) {
    if (result != null) {
      rejectIncompatibleResult(result, Void.class);
    }
    return null;
  }
  assert result != null;
  return Jackson.treeToValue(result, resultType);
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

@Nullable
private static <T> T deserializeResult(
    JsonNode result, Command<T> command) throws JsonProcessingException {
  requireNonNull(command, "command");
  // Convert null node to the real null.
  if (result != null && result.isNull()) {
    result = null;
  }
  final Class<T> resultType = Util.unsafeCast(command.type().resultType());
  if (resultType == Void.class) {
    if (result != null) {
      rejectIncompatibleResult(result, Void.class);
    }
    return null;
  }
  assert result != null;
  return Jackson.treeToValue(result, resultType);
}

代码示例来源:origin: line/centraldogma

@Nullable
private static <T> T deserializeResult(
    JsonNode result, Command<T> command) throws JsonProcessingException {
  requireNonNull(command, "command");
  // Convert null node to the real null.
  if (result != null && result.isNull()) {
    result = null;
  }
  final Class<T> resultType = Util.unsafeCast(command.type().resultType());
  if (resultType == Void.class) {
    if (result != null) {
      rejectIncompatibleResult(result, Void.class);
    }
    return null;
  }
  assert result != null;
  return Jackson.treeToValue(result, resultType);
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

/**
 * Returns the value converted from the JSON representation of {@link #content()}.
 *
 * @return the value converted from {@link #content()}
 *
 * @throws IllegalStateException if this {@link Entry} is a directory
 * @throws JsonParseException if failed to parse the {@link #content()} as JSON
 * @throws JsonMappingException if failed to convert the parsed JSON into {@code valueType}
 */
public <U> U contentAsJson(Class<U> valueType) throws JsonParseException, JsonMappingException {
  final T content = content();
  if (content instanceof TreeNode) {
    return Jackson.treeToValue((TreeNode) content, valueType);
  }
  return Jackson.readValue(contentAsText(), valueType);
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

private static List<MirrorCredential> loadCredentials(Map<String, Entry<?>> entries) throws Exception {
  final Entry<?> e = entries.get(PATH_CREDENTIALS);
  if (e == null) {
    return Collections.emptyList();
  }
  final JsonNode credentialsJson = (JsonNode) e.content();
  if (!credentialsJson.isArray()) {
    throw new RepositoryMetadataException(
        PATH_CREDENTIALS + " must be an array: " + credentialsJson.getNodeType());
  }
  if (credentialsJson.size() == 0) {
    return Collections.emptyList();
  }
  final ImmutableList.Builder<MirrorCredential> builder = ImmutableList.builder();
  for (JsonNode c : credentialsJson) {
    final MirrorCredential credential = Jackson.treeToValue(c, MirrorCredential.class);
    if (credential == null) {
      throw new RepositoryMetadataException(PATH_CREDENTIALS + " contains null.");
    }
    builder.add(credential);
  }
  return builder.build();
}

代码示例来源:origin: line/centraldogma

/**
   * Returns the value converted from the JSON representation of the specified content.
   *
   * @return the value converted from the content
   *
   * @throws IllegalStateException if the content is {@code null}
   * @throws JsonParseException if failed to parse the content as JSON
   * @throws JsonMappingException if failed to convert the parsed JSON into {@code valueType}
   */
  default <U> U contentAsJson(Class<U> valueType) throws JsonParseException, JsonMappingException {
    final T content = content();
    if (content instanceof TreeNode) {
      return Jackson.treeToValue((TreeNode) content, valueType);
    }

    return Jackson.readValue(contentAsText(), valueType);
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

/**
   * Returns the value converted from the JSON representation of the specified content.
   *
   * @return the value converted from the content
   *
   * @throws IllegalStateException if the content is {@code null}
   * @throws JsonParseException if failed to parse the content as JSON
   * @throws JsonMappingException if failed to convert the parsed JSON into {@code valueType}
   */
  default <U> U contentAsJson(Class<U> valueType) throws JsonParseException, JsonMappingException {
    final T content = content();
    if (content instanceof TreeNode) {
      return Jackson.treeToValue((TreeNode) content, valueType);
    }

    return Jackson.readValue(contentAsText(), valueType);
  }
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded

private static List<MirrorCredential> loadCredentials(Map<String, Entry<?>> entries) throws Exception {
  final Entry<?> e = entries.get(PATH_CREDENTIALS);
  if (e == null) {
    return Collections.emptyList();
  }
  final JsonNode credentialsJson = (JsonNode) e.content();
  if (!credentialsJson.isArray()) {
    throw new RepositoryMetadataException(
        PATH_CREDENTIALS + " must be an array: " + credentialsJson.getNodeType());
  }
  if (credentialsJson.size() == 0) {
    return Collections.emptyList();
  }
  final ImmutableList.Builder<MirrorCredential> builder = ImmutableList.builder();
  for (JsonNode c : credentialsJson) {
    final MirrorCredential credential = Jackson.treeToValue(c, MirrorCredential.class);
    if (credential == null) {
      throw new RepositoryMetadataException(PATH_CREDENTIALS + " contains null.");
    }
    builder.add(credential);
  }
  return builder.build();
}

相关文章