com.fasterxml.jackson.dataformat.yaml.YAMLMapper.readTree()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(145)

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

YAMLMapper.readTree介绍

暂无

代码示例

代码示例来源:origin: strimzi/strimzi-kafka-operator

public static String getContent(File file, Function<JsonNode, String> edit) {
  YAMLMapper mapper = new YAMLMapper();
  try {
    JsonNode node = mapper.readTree(file);
    return edit.apply(node);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: io.konig/konig-schemagen

private void readTags(String fileName, StringBuffer template) throws FileNotFoundException, IOException {
  File resourceFile = new File(path, fileName);
  if(resourceFile.exists()){
    try (InputStream inputStream = new FileInputStream(resourceFile)) {
      String contents = IOUtils.toString(inputStream);
      YAMLMapper mapper = new YAMLMapper(new YAMLFactory());
      JsonNode node = mapper.readTree(contents);
      JsonNode resourcesNode = node.get("Tags");
      String jsonAsYaml = new YAMLMapper().writeValueAsString(resourcesNode);
      String[] resourceLines=jsonAsYaml.split("\n");
      for(String line:resourceLines){
        if(!line.contains("---")){
          template.append(""+line+"\n      ");
        }
      }
    }
  }
}

代码示例来源:origin: strimzi/strimzi-kafka-operator

public static String changeDeploymentNamespaceUpgrade(File deploymentFile, String namespace) {
  YAMLMapper mapper = new YAMLMapper();
  try {
    JsonNode node = mapper.readTree(deploymentFile);
    // Change the docker org of the images in the 050-deployment.yaml
    ObjectNode containerNode = (ObjectNode) node.at("/spec/template/spec/containers").get(0);
    for (JsonNode envVar : containerNode.get("env")) {
      String varName = envVar.get("name").textValue();
      if (varName.matches("STRIMZI_NAMESPACE")) {
        // Replace all the default images with ones from the $DOCKER_ORG org and with the $DOCKER_TAG tag
        ((ObjectNode) envVar).remove("valueFrom");
        ((ObjectNode) envVar).put("value", namespace);
      }
    }
    return mapper.writeValueAsString(node);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: strimzi/strimzi-kafka-operator

/**
 * Changes the {@code subject} of the RoleBinding in the given YAML resource to be the
 * {@code strimzi-cluster-operator} {@code ServiceAccount} in the given namespace.
 * @param roleBindingFile
 * @param namespace
 * @return role
 */
public static String changeRoleBindingSubject(File roleBindingFile, String namespace) {
  YAMLMapper mapper = new YAMLMapper();
  try {
    JsonNode node = mapper.readTree(roleBindingFile);
    ArrayNode subjects = (ArrayNode) node.get("subjects");
    ObjectNode subject = (ObjectNode) subjects.get(0);
    subject.put("kind", "ServiceAccount")
        .put("name", "strimzi-cluster-operator")
        .put("namespace", namespace);
    return mapper.writeValueAsString(node);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: io.konig/konig-schemagen

contents = tempresult.toString();
YAMLMapper mapper = new YAMLMapper(new YAMLFactory());
JsonNode node = mapper.readTree(contents);
JsonNode outputNode=node.get("Outputs");
if(outputNode!=null){

相关文章