gpt4 book ai didi

com.vmware.admiral.common.util.YamlMapper类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 15:18:49 29 4
gpt4 key购买 nike

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

YamlMapper介绍

[英]YAML mapping functions
[中]YAML映射函数

代码示例

代码示例来源:origin: vmware/admiral

private static String[] convertDependsOn(Object dependsOn) {
  if (dependsOn == null) {
    return null;
  }
  return YamlMapper.objectMapper().convertValue(dependsOn, String[].class);
}

代码示例来源:origin: vmware/admiral

private String serializeContent(String kubeConfig) throws IOException {
  return YamlMapper.fromJsonToYaml(kubeConfig);
}

代码示例来源:origin: vmware/admiral

public String getKubernetesEntityAsJson() throws IOException {
  return YamlMapper.fromYamlToJson(kubernetesEntity);
}

代码示例来源:origin: vmware/admiral

public static Map<String, Object> serializeNestedState(NestedState nestedState)
    throws IOException {
  return serializeNestedState(nestedState, YamlMapper.objectMapper(),
      YamlMapper.objectWriter());
}

代码示例来源:origin: vmware/admiral

boolean isMultiYaml = YamlMapper.isMultiYaml(yaml);
if (isMultiYaml) {
  List<String> yamls = YamlMapper.splitYaml(yaml);
  template = YamlMapper.objectMapper().readValue(yaml, CommonDescriptionEntity.class);
} catch (JsonProcessingException e) {
  throw new LocalizableValidationException(

代码示例来源:origin: vmware/admiral

@Test
public void testSplitYamlWithSingleYaml() {
  String yamlInput = sampleYamlDefinition;
  List<String> expectedOutput = new ArrayList<>();
  expectedOutput.add(sampleYamlDefinition);
  List<String> actualOutput = YamlMapper.splitYaml(yamlInput);
  assertEquals(1, actualOutput.size());
  assertEquals(expectedOutput.get(0), actualOutput.get(0));
}

代码示例来源:origin: vmware/admiral

@Test
public void testIsValidYaml() {
  String[] inputs = new String[] { sampleYamlDefinition,
      "invalid\ninput", "{\"person\":{\"name\":\"test-name\",\"age\":14}}" };
  boolean[] expectedOutputs = new boolean[] { true, false, false };
  for (int i = 0; i < inputs.length; i++) {
    assertEquals("Test failed on iteration: " + i,
        expectedOutputs[i], YamlMapper.isValidYaml(inputs[i]));
  }
}

代码示例来源:origin: vmware/admiral

@Test
public void testIsMultiYaml() {
  String[] in = new String[] { sampleYamlDefinition,
      sampleYamlDefinition + "\n" + sampleYamlDefinition };
  boolean[] out = new boolean[] { false, true };
  assertEquals(out[0], YamlMapper.isMultiYaml(in[0]));
  assertEquals(out[1], YamlMapper.isMultiYaml(in[1]));
}

代码示例来源:origin: vmware/admiral

public static String serializeDockerCompose(DockerCompose entity) throws IOException {
  sanitizeDockerCompose(entity);
  return YamlMapper.objectWriter().writeValueAsString(entity).trim();
}

代码示例来源:origin: vmware/admiral

public static PropertyFilter createBuiltinFieldFilter() {
  return SimpleBeanPropertyFilter.serializeAllExcept(getBuiltinFieldNames());
}

代码示例来源:origin: vmware/admiral

public static List<String> splitYaml(String yaml) {
  assertNotNull(yaml, "yaml");
  yaml = removeComments(yaml);
  List<String> result = new ArrayList<>();
  if (!yaml.startsWith("---")) {
    result.add(yaml);
    return result;
  }
  String[] yamls = yaml.split(YAML_REGEX_VERIFIER);
  result = Arrays.stream(yamls)
      .filter(y -> !y.trim().equals(""))
      .collect(Collectors.toList());
  for (int i = 0; i < result.size(); i++) {
    String tempYaml = "---\n" + result.get(i).trim();
    result.set(i, tempYaml);
  }
  return result;
}

代码示例来源:origin: vmware/admiral

@Test
public void testSplitYamlWithMultipleYamls() {
  String yamlInput = sampleYamlDefinition + "\n" + sampleYamlDefinition;
  List<String> expectedOutput = new ArrayList<>();
  expectedOutput.add(sampleYamlDefinition);
  expectedOutput.add(sampleYamlDefinition);
  List<String> actualOutput = YamlMapper.splitYaml(yamlInput);
  assertEquals(2, actualOutput.size());
  assertEquals(expectedOutput.get(0), actualOutput.get(0));
  assertEquals(expectedOutput.get(1), actualOutput.get(1));
}

代码示例来源:origin: vmware/admiral

public static Map<String, Object> serializeTemplate(CompositeTemplate template)
    throws IOException {
  return serializeTemplate(template, YamlMapper.objectMapper(), YamlMapper.objectWriter());
}

代码示例来源:origin: vmware/admiral

private void validateDescription(KubernetesDescription description) throws IOException {
  if (!isValidYaml(description.kubernetesEntity)) {
    throw new LocalizableValidationException("Invalid YAML input.",
        "compute.template.yaml.invalid");
  }
  BaseKubernetesObject kubernetesEntity = description
      .getKubernetesEntity(BaseKubernetesObject.class);
  assertNotNullOrEmpty(kubernetesEntity.apiVersion, "apiVersion");
  assertNotNullOrEmpty(kubernetesEntity.kind, "kind");
  assertNotNull(kubernetesEntity.metadata, "metadata");
  assertNotNullOrEmpty(kubernetesEntity.metadata.name, "metadata.name");
  description.type = kubernetesEntity.kind;
  description.apiVersion = kubernetesEntity.apiVersion;
  description.name = kubernetesEntity.metadata.name;
  description.namespace = kubernetesEntity.metadata.namespace;
}

代码示例来源:origin: vmware/admiral

public static String serializeCompositeTemplate(CompositeTemplate entity) throws IOException {
  sanitizeCompositeTemplate(entity, true);
  Map<String, Object> stringObjectMap = TemplateSerializationUtils.serializeTemplate(entity);
  if (!isNullOrEmpty(entity.bindings)) {
    normalizeBindings(stringObjectMap, entity);
  }
  return YamlMapper.objectWriter().writeValueAsString(stringObjectMap);
}

代码示例来源:origin: vmware/admiral

public <T extends BaseKubernetesObject> T getKubernetesEntity(Class<T> type)
    throws IOException {
  return YamlMapper.objectMapper().readValue(kubernetesEntity, type);
}

代码示例来源:origin: vmware/admiral

@Test
public void testSplitYamlWithComments() {
  String yamlInput = "# comment 1 \n"
      + "#comment 2 \n"
      + sampleYamlDefinition
      + "   #   comment 3\n"
      + sampleYamlDefinition;
  List<String> expectedOutput = new ArrayList<>();
  expectedOutput.add(sampleYamlDefinition);
  expectedOutput.add(sampleYamlDefinition);
  List<String> actualOutput = YamlMapper.splitYaml(yamlInput);
  assertEquals(2, actualOutput.size());
  assertEquals(expectedOutput.get(0), actualOutput.get(0));
  assertEquals(expectedOutput.get(1), actualOutput.get(1));
}

代码示例来源:origin: vmware/admiral

@Test
public void testConvertFromYamlToJson() throws IOException {
  String yamlInput = "---\n"
      + "person:\n"
      + "  name: test-name\n"
      + "  age: 14\n";
  String expectedJsonOutput = "{\"person\":{\"name\":\"test-name\",\"age\":14}}";
  String actualJsonOutput = YamlMapper.fromYamlToJson(yamlInput);
  assertEquals(expectedJsonOutput, actualJsonOutput);
}

代码示例来源:origin: vmware/admiral

@Test
public void testConvertFromJsonToYaml() throws IOException {
  String jsonInput = "{\"person\":{\"name\":\"test-name\",\"age\":14}}";
  String expectedYamlOutput = "---\n"
      + "person:\n"
      + "  name: \"test-name\"\n"
      + "  age: 14\n";
  String actualYamlOutput = YamlMapper.fromJsonToYaml(jsonInput);
  assertEquals(expectedYamlOutput, actualYamlOutput);
}

代码示例来源:origin: vmware/admiral

public static String fromJsonToYaml(String json) throws IOException {
  JsonNode jsonNode = objectMapper().readTree(json);
  return objectMapper().writeValueAsString(jsonNode);
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com