Search in sources :

Example 16 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project spring-framework by spring-projects.

the class Jackson2ObjectMapperFactoryBeanTests method setObjectMapper.

@Test
public void setObjectMapper() {
    this.factory.setObjectMapper(new XmlMapper());
    this.factory.afterPropertiesSet();
    assertNotNull(this.factory.getObject());
    assertTrue(this.factory.isSingleton());
    assertEquals(XmlMapper.class, this.factory.getObjectType());
}
Also used : XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.Test)

Example 17 with XmlMapper

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

the class ConfigUtils method getParam.

public static <T> JsonNode getParam(T config, String pathAndProp) throws Exception {
    XmlMapper xmlMapper = xmlMapper();
    JsonNode configNode = xmlMapper.valueToTree(config);
    if (JsonPointer.compile(pathAndProp).equals(JsonPointer.compile("/"))) {
        return configNode;
    }
    JsonPointer pathPointer = JsonPointer.compile(pathAndProp);
    JsonNode pathNode = configNode.at(pathPointer);
    if (pathNode.isMissingNode() || pathNode.isNull()) {
        return null;
    }
    return pathNode;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPointer(com.fasterxml.jackson.core.JsonPointer) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 18 with XmlMapper

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

the class ConfigUtils method readConfigFromXml.

public static <T> T readConfigFromXml(Class<T> configClass, String xmlString) throws JsonProcessingException, IOException {
    ObjectMapper objectMapper = mapper();
    XmlMapper xmlMapper = xmlMapper();
    JsonNode configNode = xmlMapper.readTree(xmlString);
    T config = objectMapper.treeToValue(configNode, configClass);
    validateBean(config);
    return config;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)18 Test (org.junit.Test)9 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 BadRequestException (ninja.exceptions.BadRequestException)5 JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 NinjaTest (ninja.NinjaTest)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonPointer (com.fasterxml.jackson.core.JsonPointer)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)1 Module (com.fasterxml.jackson.databind.Module)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 BeanSerializerFactory (com.fasterxml.jackson.databind.ser.BeanSerializerFactory)1 SerializerFactory (com.fasterxml.jackson.databind.ser.SerializerFactory)1 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)1 JaxbAnnotationModule (com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)1