本文整理了Java中com.vmware.admiral.common.util.YamlMapper.objectMapper()
方法的一些代码示例,展示了YamlMapper.objectMapper()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlMapper.objectMapper()
方法的具体详情如下:
包路径:com.vmware.admiral.common.util.YamlMapper
类名称:YamlMapper
方法名:objectMapper
暂无
代码示例来源:origin: vmware/admiral
private static String[] convertDependsOn(Object dependsOn) {
if (dependsOn == null) {
return null;
}
return YamlMapper.objectMapper().convertValue(dependsOn, String[].class);
}
代码示例来源:origin: vmware/admiral
public <T extends BaseKubernetesObject> T getKubernetesEntity(Class<T> type)
throws IOException {
return YamlMapper.objectMapper().readValue(kubernetesEntity, type);
}
代码示例来源:origin: vmware/admiral
public static String fromJsonToYaml(String json) throws IOException {
JsonNode jsonNode = objectMapper().readTree(json);
return objectMapper().writeValueAsString(jsonNode);
}
代码示例来源:origin: vmware/admiral
public static boolean isValidYaml(String yaml) {
if (yaml == null || yaml.startsWith("{")) {
return false;
}
try {
objectMapper().readValue(yaml, Map.class);
} catch (IOException ex) {
return false;
}
return true;
}
}
代码示例来源:origin: vmware/admiral
public static String serializeKubernetesEntity(BaseKubernetesObject kubernetesEntity)
throws IOException {
return YamlMapper.objectMapper().setSerializationInclusion(Include.NON_NULL)
.writeValueAsString(kubernetesEntity).trim();
}
代码示例来源:origin: vmware/admiral
public static String fromYamlToJson(String yaml) throws IOException {
Object obj = objectMapper().readValue(yaml, Object.class);
return Utils.toJson(obj);
}
代码示例来源:origin: vmware/admiral
public static NestedState deserializeServiceDocument(
Map<String, Object> value, Class<? extends ServiceDocument> type) {
return deserializeServiceDocument(value, type, YamlMapper.objectMapper());
}
代码示例来源:origin: vmware/admiral
public static CompositeTemplate deserializeTemplate(Map<String, Object> initialMap) {
return deserializeTemplate(initialMap, YamlMapper.objectMapper());
}
代码示例来源:origin: vmware/admiral
public static BaseKubernetesObject deserializeKubernetesEntity(String yaml)
throws IOException {
assertNotEmpty(yaml, "yaml");
BaseKubernetesObject entity;
try {
entity = YamlMapper.objectMapper().readValue(yaml.trim(), BaseKubernetesObject.class);
if (POD_TYPE.equals(entity.kind)) {
entity = YamlMapper.objectMapper().readValue(yaml.trim(), Pod.class);
} else if (POD_TEMPLATE.equals(entity.kind)) {
entity = YamlMapper.objectMapper().readValue(yaml.trim(), PodTemplate.class);
} else if (REPLICATION_CONTROLLER_TYPE.equals(entity.kind)) {
entity = YamlMapper.objectMapper().readValue(yaml.trim(),
ReplicationController.class);
} else if (DEPLOYMENT_TYPE.equals(entity.kind)) {
entity = YamlMapper.objectMapper().readValue(yaml.trim(), Deployment.class);
} else if (SERVICE_TYPE.equals(entity.kind)) {
entity = YamlMapper.objectMapper().readValue(yaml.trim(), Service.class);
} else {
entity = YamlMapper.objectMapper().readValue(yaml.trim(),
BaseKubernetesObject.class);
}
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(
"Error processing Kubernetes configuration YAML content: " + e
.getOriginalMessage());
}
return entity;
}
代码示例来源:origin: vmware/admiral
@SuppressWarnings("unchecked")
public void merge(BaseKubernetesObject copyFrom) {
Map<String, Object> copyTo;
try {
copyTo = YamlMapper.objectMapper().readValue(kubernetesEntity, Map.class);
} catch (Exception e) {
Utils.logWarning("Could not read value of kubernetes entity from yaml, reason :%s",
Utils.toString(e));
return;
}
Map<String, Object> copyFromMap = YamlMapper.objectMapper().convertValue(copyFrom,
Map.class);
copyTo.putAll(copyFromMap);
try {
kubernetesEntity = YamlMapper.objectMapper().writeValueAsString(copyTo);
} catch (JsonProcessingException e) {
Utils.logWarning("Could not write of kubernetes entity to yaml, reason :%s",
Utils.toString(e));
}
}
}
代码示例来源:origin: vmware/admiral
public static Map<String, Object> serializeTemplate(CompositeTemplate template)
throws IOException {
return serializeTemplate(template, YamlMapper.objectMapper(), YamlMapper.objectWriter());
}
代码示例来源:origin: vmware/admiral
public static Map<String, Object> serializeNestedState(NestedState nestedState)
throws IOException {
return serializeNestedState(nestedState, YamlMapper.objectMapper(),
YamlMapper.objectWriter());
}
代码示例来源:origin: vmware/admiral
@SuppressWarnings("unchecked")
private static <T> ComponentTemplate<T> createTemplate(String type, Object data) {
assertNotNull(data, "data");
ComponentTemplate<T> template = new ComponentTemplate<>();
template.type = type;
Class<?> descriptionClass = getDescriptionClass(type);
if (descriptionClass.equals(ContainerDescription.class)) {
descriptionClass = CompositeTemplateContainerDescription.class;
}
template.data = (T) YamlMapper.objectMapper().convertValue(data, descriptionClass);
return template;
}
代码示例来源:origin: vmware/admiral
public static DockerCompose deserializeDockerCompose(String yaml) throws IOException {
assertNotEmpty(yaml, "yaml");
DockerCompose entity;
try {
entity = YamlMapper.objectMapper().readValue(yaml.trim(),
DockerCompose.class);
} catch (JsonProcessingException e) {
throw new LocalizableValidationException(
"Error processing Docker Compose v2 YAML content: " + e.getOriginalMessage(),
"compute.template.yaml.compose2.error", e.getOriginalMessage());
}
sanitizeDockerCompose(entity);
return entity;
}
代码示例来源:origin: vmware/admiral
@SuppressWarnings("rawtypes")
public static void assertEqualsYamls(String expected, String actual, boolean ignoreEmptyValues) throws IOException {
Map expectedMap = YamlMapper.objectMapper().readValue(expected, Map.class);
Map actualMap = YamlMapper.objectMapper().readValue(actual, Map.class);
if (ignoreEmptyValues) {
removeEmptyValues(expectedMap);
removeEmptyValues(actualMap);
}
Logger.getLogger(CompositeTemplateUtilTest.class.getName()).log(Level.INFO,
"ignoreEmptyValues: " + ignoreEmptyValues +
" \nassertEqualsYamls : expected=<" + YamlMapper.objectMapper().writeValueAsString(expectedMap) +
"> and actual=<" + YamlMapper.objectMapper().writeValueAsString(actualMap) + ">");
assertEquals(expectedMap, actualMap);
}
代码示例来源:origin: vmware/admiral
@SuppressWarnings("unchecked")
public static CompositeTemplate deserializeCompositeTemplate(String yaml) throws IOException {
assertNotEmpty(yaml, "yaml");
CompositeTemplate entity;
try {
Map<String, Object> deserialized = YamlMapper.objectMapper().readValue(yaml.trim(),
Map.class);
List<Binding.ComponentBinding> componentBindings = BindingUtils
.extractBindings(deserialized);
entity = TemplateSerializationUtils.deserializeTemplate(deserialized);
entity.bindings = new ArrayList<>(componentBindings);
} catch (JsonProcessingException e) {
String format = "Error processing Blueprint YAML content: %s";
Utils.logWarning(format, e.getMessage());
throw new LocalizableValidationException(String.format(format, e.getOriginalMessage()),
"compute.template.yaml.error", e.getOriginalMessage());
}
sanitizeCompositeTemplate(entity, false);
return entity;
}
代码示例来源:origin: vmware/admiral
template = YamlMapper.objectMapper().readValue(yaml, CommonDescriptionEntity.class);
} catch (JsonProcessingException e) {
throw new LocalizableValidationException(
代码示例来源:origin: vmware/admiral
@Test
public void testMapper() throws Exception {
URL templateUrl = getClass().getClassLoader().getResource(
"WordPress_with_MySQL_containers.yaml");
ObjectMapper mapper = YamlMapper.objectMapper();
CompositeTemplate bp = mapper.readValue(templateUrl, CompositeTemplate.class);
assertEquals("id", null, bp.id);
assertEquals("name", "wordPressWithMySql", bp.name);
assertNotNull("properties", bp.properties);
assertEquals("properties.size", 1, bp.properties.size());
assertNotNull("components", bp.components);
assertEquals("components.size", 2, bp.components.size());
ComponentTemplate<?> mysqlComponent = bp.components.get("mysql");
assertNotNull("components[mysql]", mysqlComponent);
assertEquals("components[mysql].type", ResourceType.CONTAINER_TYPE.getContentType(),
mysqlComponent.type);
}
}
代码示例来源:origin: vmware/admiral
assertTrue(resultYaml.contains("${_resource~mysql~address}:3306"));
Map<String, Object> templateMap = YamlMapper.objectMapper().readValue(originalYaml.trim(), Map.class);
Map<String, Object> resultMap = YamlMapper.objectMapper().readValue(resultYaml.trim(), Map.class);
assertEquals(templateMap.get("components"), resultMap.get("components"));
代码示例来源:origin: vmware/admiral
@Test
public void testMapping() throws Exception {
ObjectMapper mapper = YamlMapper.objectMapper();
内容来源于网络,如有侵权,请联系作者删除!