Search in sources :

Example 36 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project streamline by hortonworks.

the class ConfigFileReader method readConfigFromHadoopXmlType.

private Map<String, String> readConfigFromHadoopXmlType(InputStream configFileStream) throws IOException {
    ObjectReader reader = new XmlMapper().reader();
    HadoopXml hadoopXml = reader.forType(HadoopXml.class).readValue(configFileStream);
    Map<String, String> configMap = new HashMap<>();
    for (HadoopXml.HadoopXmlProperty property : hadoopXml.getProperties()) {
        configMap.put(property.getName(), property.getValue());
    }
    return configMap;
}
Also used : HashMap(java.util.HashMap) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 37 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project jocean-http by isdom.

the class MessageUtil method unserializeAsXml.

public static <T> T unserializeAsXml(final InputStream is, final Class<T> type) {
    final XmlMapper mapper = new XmlMapper();
    mapper.addHandler(new DeserializationProblemHandler() {

        @Override
        public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser p, final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName) throws IOException {
            LOG.warn("UnknownProperty [{}], just skip", propertyName);
            p.skipChildren();
            return true;
        }
    });
    try {
        return mapper.readValue(is, type);
    } catch (Exception e) {
        LOG.warn("exception when parse as xml, detail: {}", ExceptionUtils.exception2detail(e));
        return null;
    }
}
Also used : DeserializationProblemHandler(com.fasterxml.jackson.databind.deser.DeserializationProblemHandler) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) HttpObject(io.netty.handler.codec.http.HttpObject) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 38 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cypher-for-gremlin by opencypher.

the class TckResultsComparator method getFeatures.

private static Features getFeatures(String reportPath) throws IOException {
    File reportFile = new File(reportPath);
    checkState(reportFile.exists(), format("File %s doesn't exist, but is required for TCK reports comparison.", reportPath));
    ObjectMapper xmlMapper = new XmlMapper();
    xmlMapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE);
    xmlMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    Feature value = xmlMapper.readValue(reportFile, Feature.class);
    return new Features(new Feature[] { value });
}
Also used : File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 39 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project metron by apache.

the class PcapServiceImpl method getPdml.

@Override
public Pdml getPdml(String username, String jobId, Integer page) throws RestException {
    Pdml pdml = null;
    Path path = getPath(username, jobId, page);
    try {
        FileSystem fileSystem = getFileSystem();
        if (path != null && fileSystem.exists(path)) {
            String scriptPath = environment.getProperty(MetronRestConstants.PCAP_PDML_SCRIPT_PATH_SPRING_PROPERTY);
            InputStream processInputStream = pcapToPdmlScriptWrapper.execute(scriptPath, fileSystem, path);
            pdml = new XmlMapper().readValue(processInputStream, Pdml.class);
            processInputStream.close();
        }
    } catch (IOException e) {
        throw new RestException(e);
    }
    return pdml;
}
Also used : Path(org.apache.hadoop.fs.Path) Pdml(org.apache.metron.rest.model.pcap.Pdml) InputStream(java.io.InputStream) FileSystem(org.apache.hadoop.fs.FileSystem) RestException(org.apache.metron.rest.RestException) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 40 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project CzechIdMng by bcvsolutions.

the class AbstractReleaseManager method hasParentModule.

/**
 * If module has parent defined.
 *
 * @param moduleName
 * @return true = is submodule.
 */
protected boolean hasParentModule(String moduleName) {
    File modulePackage = new File(String.format("%s/pom.xml", getBackendModuleBasePath(moduleName)));
    Assert.isTrue(modulePackage.exists(), String.format("Backend module [%s] not found on filesystem.", moduleName));
    // 
    try {
        XmlMapper xmlMapper = new XmlMapper();
        JsonNode json = xmlMapper.readTree(modulePackage);
        // 
        return json.get("parent") != null;
    } catch (Exception ex) {
        throw new ReleaseException(ex);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) File(java.io.File) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)62 IOException (java.io.IOException)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Test (org.junit.Test)15 InputStream (java.io.InputStream)9 File (java.io.File)8 HttpResponse (org.apache.http.HttpResponse)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.jupiter.api.Test)5 BadRequestException (ninja.exceptions.BadRequestException)4 EntityReferences (org.apache.cloudstack.backup.veeam.api.EntityReferences)4 Ref (org.apache.cloudstack.backup.veeam.api.Ref)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)2 FileInputStream (java.io.FileInputStream)2