Skip to content

Instantly share code, notes, and snippets.

@maxandersen
Created December 6, 2022 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxandersen/4a22c2a7d5faea8fa241fee72fa4dd8b to your computer and use it in GitHub Desktop.
Save maxandersen/4a22c2a7d5faea8fa241fee72fa4dd8b to your computer and use it in GitHub Desktop.
///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