com.fasterxml.jackson.dataformat.yaml.YAMLParser Java Examples

The following examples show how to use com.fasterxml.jackson.dataformat.yaml.YAMLParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YamlConfigurationParser.java    From springboot-plugin-framework-parent with Apache License 2.0 5 votes vote down vote up
@Override
protected Object parse(Resource resource, Class<?> pluginConfigClass)
        throws Exception{
    InputStream input = new FileInputStream(resource.getFile());
    YAMLParser yamlParser = yamlFactory.createParser(input);
    final JsonNode node = objectMapper.readTree(yamlParser);
    if(node == null){
        return pluginConfigClass.newInstance();
    }
    TreeTraversingParser treeTraversingParser = new TreeTraversingParser(node);
    return objectMapper.readValue(treeTraversingParser, pluginConfigClass);
}
 
Example #2
Source File: JsonNodeYamlParser.java    From bootique with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #3
Source File: YamlReader.java    From bootique with Apache License 2.0 5 votes vote down vote up
static JsonNode read(String yaml) {

        ByteArrayInputStream in = new ByteArrayInputStream(yaml.getBytes());

        try {
            YAMLParser parser = new YAMLFactory().createParser(in);
            return new ObjectMapper().readTree(parser);
        } catch (IOException e) {
            throw new RuntimeException("Error reading yaml: " + yaml, e);
        }
    }
 
Example #4
Source File: YamlMapper.java    From digdag with Apache License 2.0 5 votes vote down vote up
public <T> T readFile(File file, Class<T> type)
    throws IOException
{
    // TODO use yaml if file path ends with dig or yml, otherwise use json?
    try (YAMLParser out = yaml.createParser(new FileInputStream(file))) {
        // TODO write to a String first, then write to file. to not create partially-written broken file
        return mapper.readValue(out, type);
    }
}
 
Example #5
Source File: KubeCloudImageImpl.java    From teamcity-kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
KubeCloudImageImpl(@NotNull final KubeCloudImageData kubeCloudImageData,
                   @NotNull final KubeApiConnector apiConnector) {
    myImageData = kubeCloudImageData;
    final String templateContent = myImageData.getCustomPodTemplateContent();
    if (StringUtil.isEmpty(templateContent)){
        myPodTemplate = null;
        myPVCTemplate = null;
    } else if (templateContent.contains("\n---\n")){
        final String processedContent;
        final String placeholderReplacement = "__INSTANCE__ID__";
        if (templateContent.contains("%instance.id%")){
            processedContent = templateContent.replaceAll("%instance.id%", placeholderReplacement);
        } else {
            processedContent = templateContent;
        }
        YAMLFactory factory = new YAMLFactory();
        ObjectMapper mapper = new ObjectMapper();
        final AtomicReference<String> podTemplateRef = new AtomicReference<>();
        final AtomicReference<String> pvcTemplateRef = new AtomicReference<>();
        try {
            YAMLParser parser = factory.createParser(processedContent);
            List<ObjectNode> list = mapper.readValues(parser, ObjectNode.class).readAll();
            list.forEach(node->{
                if (node.get("kind") != null && "Pod".equals(node.get("kind").textValue())){
                    if (podTemplateRef.get() != null){
                       throw new RuntimeException("More than one Pod template is specified for image " + myImageData.getAgentNamePrefix());
                    }
                    podTemplateRef.set(node.toString().replaceAll(placeholderReplacement, "%instance.id%"));
                } else if (node.get("kind") != null && "PersistentVolumeClaim".equals(node.get("kind").textValue())){
                    if (pvcTemplateRef.get() != null){
                        throw new RuntimeException("More than one PVC template is specified for image " + myImageData.getAgentNamePrefix());
                    }
                    pvcTemplateRef.set(node.toString().replaceAll(placeholderReplacement, "%instance.id%"));
                } else{
                    throw new RuntimeException("Unknown yaml template is specified for image " + myImageData.getAgentNamePrefix());
                }
            });
        } catch (IOException e) {
            ExceptionUtil.rethrowAsRuntimeException(e);
        }
        myPodTemplate = podTemplateRef.get();
        myPVCTemplate = pvcTemplateRef.get();
    } else {
        myPodTemplate = templateContent;
        myPVCTemplate = null;
    }
    myApiConnector = apiConnector;
}
 
Example #6
Source File: DeserializerTestBase.java    From bootique with Apache License 2.0 4 votes vote down vote up
protected <T> T deserialize(Class<T> type, String yml) throws IOException {
    YAMLParser parser = new YAMLFactory().createParser(yml);
    return jacksonService.newObjectMapper().readValue(parser, type);
}