/** * 序列化为YAML */ public static <V> String toYaml(V v) { try { return yamlMapper.writeValueAsString(v); } catch (JsonProcessingException e) { log.error("jackson to yaml error, obj: {}", v, e); return null; } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper(); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper(); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper(); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper(); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String toString() { YAMLMapper mapper = new YAMLMapper().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
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 "); } } } } }
@RequestMapping(value = "/swaggerDetailed.yaml", method = RequestMethod.GET, produces = "application/yaml") public String getProjectSwaggerYaml() { ObjectMapper jsonWriter = new ObjectMapper() .setSerializationInclusion(JsonInclude.Include.NON_NULL); YAMLMapper yamlMapper = new YAMLMapper() .disable(WRITE_DOC_START_MARKER); try { Swagger swagger = swaggerGenerator.generateSwagger(); JsonNode jsonNode = jsonWriter.readTree( jsonWriter.writeValueAsBytes(swagger)); return yamlMapper.writeValueAsString(jsonNode); } catch (IOException e) { throw new RestAPIException("An error occurred while generating Swagger documentation", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, e); } }
/** * 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); } }
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); } }
public String toYaml(String version) throws IOException { JsonNode jsonNodeTree = new ObjectMapper().readTree(this.toJson(version).toString()); return new YAMLMapper().writeValueAsString(jsonNodeTree); }