List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLMapper YAMLMapper
public YAMLMapper()
From source file:com.reprezen.kaizen.oasparser.jsonoverlay.gen.CodeGenerator.java
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException, ParseException { Opts opts = new Opts(args); Object parsedYaml = new Yaml().load(new FileInputStream(opts.typeDataFile)); TypeData typeData = new YAMLMapper().convertValue(parsedYaml, TypeData.class); typeData.init();// ww w . jav a2s . c om new CodeGenerator(opts).generate(typeData); }
From source file:com.memtrip.gear2nd.parser.Deserialization.java
private static YAMLMapper getYAMLMapper() { YAMLMapper yamlMapper = new YAMLMapper(); yamlMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); yamlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); return yamlMapper; }
From source file:cat.calidos.morfeu.model.transform.TransformTezt.java
protected String transformYAMLToXML(String yamlPath, String documentPath) throws Exception { YAMLMapper mapper = new YAMLMapper(); File inputFile = new File(yamlPath); String content = FileUtils.readFileToString(inputFile, Config.DEFAULT_CHARSET); JsonNode yaml = mapper.readTree(content); Document doc = produceDocumentFromPath(documentPath); assertNotNull(doc);/*w w w. j a v a 2 s .co m*/ Map<String, Object> values = new HashMap<String, Object>(2); values.put("yaml", yaml); values.put("cellmodels", doc.getModel().getRootCellModels()); values.put("case", "yaml-to-xml"); return DaggerViewComponent.builder().withTemplate("templates/transform/content-yaml-to-xml.twig") .withValue(values).build().render(); // sed -E 's/\$(.+)?\$/\$\1\$ $(- set zzzz = deb("\1") -)$/g' }
From source file:com.reprezen.swaggerparser.test.DerefTest.java
@Test public void test() throws JsonProcessingException, IOException { URL modelUrl = DerefTest.class.getResource("/models/petstore-expanded.yaml"); Object parsedYaml = new Yaml().load(modelUrl.openStream()); JsonNode tree = new YAMLMapper().convertValue(parsedYaml, JsonNode.class); final OpenApi3 model = (OpenApi3) new OpenApiParser().parse(modelUrl); model.validate();//from w w w .j av a 2 s. com JsonNode aReallyImportantNode = ((SchemaImpl) model.getPath("/pets").getPost().getResponse("200") .getContentMediaType("application/json").getSchema()).getDereferencedJsonTree(); JsonNode anotherReallyImportantNode = ((ResponseImpl) model.getPath("/pets").getPost().getResponse("200")) .getDereferencedJsonTree(); System.out.println(aReallyImportantNode); System.out.println(anotherReallyImportantNode); }
From source file:com.reprezen.swaggerparser.test.BigParseTest.java
@Test public void test() throws JsonProcessingException, IOException { Object parsedYaml = new Yaml().load(modelUrl.openStream()); JsonNode tree = new YAMLMapper().convertValue(parsedYaml, JsonNode.class); final OpenApi3 model = (OpenApi3) new OpenApiParser().parse(modelUrl, false); Predicate<JsonNode> valueNodePredicate = new Predicate<JsonNode>() { @Override/*from w w w . j a v a2s .c o m*/ public boolean apply(JsonNode node) { return node.isValueNode(); } }; WalkMethod valueChecker = new WalkMethod() { @Override public void run(JsonNode node, Collection<PathKey> path) { System.out.println(StringUtils.join(path, ".")); Object fromModel = getFromModelObject((OpenApi3Impl) model, Queues.newArrayDeque(path)); Object fromJson = getValue(node); assertEquals(fromJson, fromModel); } }; JsonTreeWalker.walkTree(tree, valueNodePredicate, valueChecker); }
From source file:cat.calidos.morfeu.model.transform.TransformNoValueIntTest.java
@Test public void testTransformJSONToYAML() throws Exception { Document doc = produceDocumentFromPath("test-resources/documents/document4.json"); assertNotNull(doc);/*from w w w. j av a 2 s . c o m*/ Map<String, Object> values = new HashMap<String, Object>(2); values.put("cells", doc.getContent().asList()); values.put("model", doc.getModel()); String transformed = DaggerViewComponent.builder().withTemplate("templates/transform/content-to-yaml.twig") .withValue(values).build().render(); //System.err.println(transformed); YAMLMapper mapper = new YAMLMapper(); JsonNode yaml = mapper.readTree(transformed); assertNotNull(yaml); assertTrue(yaml.isObject()); assertTrue(yaml.has("rows")); JsonNode col = yaml.get("rows").get(0).get("cols").get(0); //rows/cols/col assertNotNull(col); assertTrue(col.isObject()); assertTrue(col.has("stuff")); assertTrue(col.has("data4")); JsonNode stuff = col.get("stuff"); assertTrue(stuff.isArray()); assertEquals("stuff : [] in transformed yaml should have no elements", 0, stuff.size()); JsonNode data4 = col.get("data4"); assertTrue(data4.isObject()); assertEquals("data4: {} in transformed yaml should be empty", 0, data4.size()); }
From source file:com.hortonworks.streamline.streams.catalog.configuration.ConfigFileWriterTest.java
@Test public void writeYamlConfigToFile() throws Exception { Map<String, String> configuration = createDummyConfiguration(); File destPath = Files.createTempFile("config", "yaml").toFile(); destPath.deleteOnExit();/* ww w . jav a2 s . c o m*/ writer.writeConfigToFile(ConfigFileType.YAML, configuration, destPath); assertTrue(destPath.exists()); try (InputStream is = new FileInputStream(destPath)) { String content = IOUtils.toString(is); System.out.println("Test print: yaml content - " + content); ObjectMapper mapper = new YAMLMapper(); Map<String, Object> readConfig = mapper.readValue(content, Map.class); assertEquals(configuration, readConfig); } }
From source file:cat.calidos.morfeu.model.injection.ContentSaverParserIntTest.java
@Test public void testSaveToYAML() throws Exception { String outputPath = temporaryOutputFilePath() + ".yaml"; URI outputURI = new URI("file://" + outputPath); FileSaver saver = DaggerContentSaverParserComponent.builder().from(content).to(outputURI).having(contentURI) .model(modelURI).withModelFetchedFrom(modelFetchableURI).build().saver().get(); saver.save();//from ww w.j a v a 2 s .c om File savedFile = new File(outputPath); assertTrue("Saver component did not create a file", savedFile.exists()); savedFile.deleteOnExit(); String writtenContent = FileUtils.readFileToString(savedFile, Config.DEFAULT_CHARSET); YAMLMapper mapper = new YAMLMapper(); JsonNode yaml = mapper.readTree(writtenContent); assertNotNull(yaml); assertTrue(yaml.isObject()); assertTrue(yaml.has("rows")); JsonNode rows = yaml.get("rows"); //rows assertNotNull(rows); assertTrue(rows.isArray()); assertEquals(1, rows.size()); }
From source file:cat.calidos.morfeu.model.injection.URIToParsedModule.java
@Produces
YAMLMapper yamlMapper() {
return new YAMLMapper();
}
From source file:com.predic8.membrane.core.interceptor.apimanagement.ApiManagementConfiguration.java
private void parseAndConstructConfiguration(InputStream is) throws IOException { String yamlSource = null;/*from w w w .ja v a2 s. co m*/ try { yamlSource = IOUtils.toString(is); } catch (IOException e) { log.warn("Could not read stream"); return; } YAMLMapper mapper = new YAMLMapper(); Map<String, Object> yaml = null; try { yaml = mapper.readValue(yamlSource, Map.class); } catch (IOException e) { log.warn("Could not parse yaml"); return; } setPolicies(parsePolicies(yaml)); setKeys(parsePoliciesForKeys(yaml)); is.close(); setUnauthorizedKey(); log.info("Configuration loaded. Notifying observers"); notifyConfigChangeObservers(); }