JsonNodeYamlParser implements Function<InputStream, Optional<JsonNode>> { @Override public Optional<JsonNode> apply(InputStream t) { try { YAMLParser parser = yamlFactory.createParser(t); return Optional.ofNullable(mapper.readTree(parser)); } catch (IOException e) { throw new RuntimeException("Error reading config data", e); } } JsonNodeYamlParser(ObjectMapper mapper); @Override Optional<JsonNode> apply(InputStream t);  }
@Test public void testApply() { InputStream in = new ByteArrayInputStream("a: b\nb: c".getBytes()); ObjectMapper mapper = new ObjectMapper(); Optional<JsonNode> node = new JsonNodeYamlParser(mapper).apply(in); assertTrue(node.isPresent()); assertEquals("b", node.get().get("a").asText()); assertEquals("c", node.get().get("b").asText()); }