You can read yaml files using jackson's objectmapper, and then give it any type you want. A very basic example for your above yaml would be:
File test_yaml.yaml:
myObject:
key1: value1
key2: value2
key3: value3
Code:
package yaml;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
public class YamlMapParser {
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
InputStream resource = YamlMapParser.class.getResourceAsStream("/yaml/test_yaml.yaml");
Map readValue = mapper.readValue(resource, Map.class);
System.out.println(readValue);
}
}
The important bit is to give Jackson's ObjectMapper a YAMLFactory to work with.
The above code then prints:
{myObject={key1=value1, key2=value2, key3=value3}}
I hope that helps!
Artur