Search in sources :

Example 26 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project tikxml by Tickaroo.

the class JacksonMediumXmlBenchmark method parse.

public void parse(String xml) throws Exception {
    XmlMapper mapper = new XmlMapper();
    Feed feed = mapper.readValue(xml, Feed.class);
    System.out.println(getClass().getSimpleName() + " " + feed);
}
Also used : XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 27 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 28 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 29 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 30 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project tutorials by eugenp.

the class SimpleBeanForCapitalizedFields method whenJavaSerializedToXmlFile_thenCorrect.

@Test
public void whenJavaSerializedToXmlFile_thenCorrect() throws IOException {
    XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.writeValue(new File("target/simple_bean.xml"), new SimpleBean());
    File file = new File("target/simple_bean.xml");
    assertNotNull(file);
}
Also used : File(java.io.File) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.Test)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)33 Test (org.junit.Test)15 IOException (java.io.IOException)8 JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 BadRequestException (ninja.exceptions.BadRequestException)5 File (java.io.File)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)2 DeserializationProblemHandler (com.fasterxml.jackson.databind.deser.DeserializationProblemHandler)2 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)2 HashMap (java.util.HashMap)2 NinjaTest (ninja.NinjaTest)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonPointer (com.fasterxml.jackson.core.JsonPointer)1 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1