public static void prettyPrint(Object o) { try { System.out.println(pretty().writeValueAsString(o)); } catch (Exception e) { e.printStackTrace(); } } }
public static String pretty(Object o) { try { return pretty().writeValueAsString(o); } catch (Exception e) { e.printStackTrace(); return null; } }
@Test public void testMultiLineYaml() throws Exception { final String yaml = "multiLineString: |\n" + " \"hello multiple lines\n" + " in my content without\n" + " any problem\"\n"; JsonNode node = Yaml.mapper().readValue(yaml, JsonNode.class); String serializedYaml = Yaml.pretty(node); assertEquals(serializedYaml, yaml); }
@Test public void testQuotedStrings() throws Exception { final String yaml = "singleLineUnquotedString: Look ma no quotes\n"; JsonNode node = Yaml.mapper().readValue(yaml, JsonNode.class); String serializedYaml = Yaml.pretty(node); assertEquals(serializedYaml, yaml); }
@Test public void testPreserveQuotesOnNumbers() throws Exception { final String yaml = "quotedNumber: \"3.0\"\n"; JsonNode node = Yaml.mapper().readValue(yaml, JsonNode.class); String serializedYaml = Yaml.pretty(node); assertEquals(serializedYaml, yaml); }
@Test public void testPreserveNoQuotesOnNumbers() throws Exception { final String yaml = "unquotedNumber: 4.0\n"; JsonNode node = Yaml.mapper().readValue(yaml, JsonNode.class); String serializedYaml = Yaml.pretty(node); assertEquals(serializedYaml, yaml); }
@Test public void testPreserveNoQuotesOnNonNumbers() throws Exception { final String yaml = "unquotedNumber: 4.0.0\n"; JsonNode node = Yaml.mapper().readValue(yaml, JsonNode.class); String serializedYaml = Yaml.pretty(node); assertEquals(serializedYaml, yaml); } }
private static void apply(Object objectToSerialize, String str, ObjectMapper mapper) { final ObjectNode lhs = mapper.convertValue(objectToSerialize, ObjectNode.class); ObjectNode rhs = null; try { rhs = mapper.readValue(str, ObjectNode.class); } catch (IOException e) { LOGGER.error("Failed to read value", e); } if (!lhs.equals(new ObjectNodeComparator(), rhs)) { assertEquals(Yaml.pretty(lhs), Yaml.pretty(rhs)); //fail(String.format("Serialized object:\n%s\ndoes not equal to expected serialized string:\n%s", lhs, rhs)); } }
resp.setContentType(APPLICATION_YAML); PrintWriter pw = resp.getWriter(); pw.write(pretty ? Yaml.pretty(oas) : Yaml.mapper().writeValueAsString(oas)); pw.close(); } else {
headers.add("Content-Type", "application/yaml"); if (prettyPrint) { out.write(Yaml.pretty().writeValueAsBytes(data)); } else { out.write(Yaml.mapper().writeValueAsBytes(data));
openapiYaml = Yaml.pretty(openAPI); } else { openapiYaml = Yaml.mapper().writeValueAsString(openAPI);
.entity(pretty ? Yaml.pretty(oas) : Yaml.mapper().writeValueAsString(oas)) .type("application/yaml") .build();
openapiYaml = Yaml.pretty(openAPI); } else { openapiYaml = Yaml.mapper().writeValueAsString(openAPI);
public static String pretty(Object o) { try { return pretty().writeValueAsString(o); } catch (Exception e) { e.printStackTrace(); return null; } }
public static void prettyPrint(Object o) { try { System.out.println(pretty().writeValueAsString(o)); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void preprocessOpenAPI(OpenAPI openAPI) { super.preprocessOpenAPI(openAPI); try { String valueAsString = Yaml.pretty(openAPI); String outputFile = outputFolder + File.separator + this.outputFile; FileUtils.writeStringToFile(new File(outputFile), valueAsString); LOGGER.debug("wrote file to " + outputFile); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
public OpenAPIService() { mapper = Json.mapper(); mapper.registerModule(new Jdk8Module()); yamlMapper = Yaml.mapper(); writer = Yaml.pretty(); }
resp.setContentType(APPLICATION_YAML); PrintWriter pw = resp.getWriter(); pw.write(pretty ? Yaml.pretty(oas) : Yaml.mapper().writeValueAsString(oas)); pw.close(); } else {
headers.add("Content-Type", "application/yaml"); if (prettyPrint) { out.write(Yaml.pretty().writeValueAsBytes(data)); } else { out.write(Yaml.mapper().writeValueAsBytes(data));
return Yaml.pretty(converter.convert(result).getOpenAPI()); } catch (LSCompilerException e) { return "Error";