Created
December 6, 2022 05:03
-
-
Save maxandersen/4a22c2a7d5faea8fa241fee72fa4dd8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//JAVA 17+ | |
//DEPS com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.0 | |
import static java.lang.System.out; | |
import java.io.IOException; | |
import com.fasterxml.jackson.core.type.TypeReference; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | |
import com.fasterxml.jackson.dataformat.yaml.YAMLParser; | |
public class yamo { | |
public static void main(String... args) throws IOException { | |
String input = """ | |
///usr/bin/env jbang --quiet camel@apache/camel pipe "$0" "$@" ; exit $? | |
--- | |
# camel-k: language=yaml | |
# Will upper-case the input | |
- from: | |
uri: "stream:in" | |
steps: | |
- setBody: | |
simple: "${body.toUpperCase()}" | |
- to: "stream:out" | |
"""; | |
var yaml = new YAMLFactory(); | |
var mapper = new ObjectMapper(yaml); | |
YAMLParser parser = yaml.createParser(input); | |
var result = mapper.readValues(parser, new TypeReference<Object>() { | |
}).readAll(); | |
out.println(result.get(0).getClass()); | |
out.println(result.get(0)); | |
out.println(result.get(1).getClass()); | |
out.println(result.get(1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment