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;
}
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;
}
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());
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project camel by apache.
the class JacksonXMLDataFormat method doStart.
@Override
protected void doStart() throws Exception {
if (xmlMapper == null) {
xmlMapper = new XmlMapper();
}
if (enableJaxbAnnotationModule) {
// Enables JAXB processing
JaxbAnnotationModule module = new JaxbAnnotationModule();
LOG.info("Registering module: {}", module);
xmlMapper.registerModule(module);
}
if (useList) {
setCollectionType(ArrayList.class);
}
if (include != null) {
JsonInclude.Include inc = getCamelContext().getTypeConverter().mandatoryConvertTo(JsonInclude.Include.class, include);
xmlMapper.setSerializationInclusion(inc);
}
if (prettyPrint) {
xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
}
if (enableFeatures != null) {
Iterator<Object> it = ObjectHelper.createIterator(enableFeatures);
while (it.hasNext()) {
String enable = it.next().toString();
// it can be different kind
SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, enable);
if (sf != null) {
xmlMapper.enable(sf);
continue;
}
DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, enable);
if (df != null) {
xmlMapper.enable(df);
continue;
}
MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, enable);
if (mf != null) {
xmlMapper.enable(mf);
continue;
}
throw new IllegalArgumentException("Enable feature: " + enable + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]");
}
}
if (disableFeatures != null) {
Iterator<Object> it = ObjectHelper.createIterator(disableFeatures);
while (it.hasNext()) {
String disable = it.next().toString();
// it can be different kind
SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, disable);
if (sf != null) {
xmlMapper.disable(sf);
continue;
}
DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, disable);
if (df != null) {
xmlMapper.disable(df);
continue;
}
MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, disable);
if (mf != null) {
xmlMapper.disable(mf);
continue;
}
throw new IllegalArgumentException("Disable feature: " + disable + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]");
}
}
if (modules != null) {
for (Module module : modules) {
LOG.info("Registering module: {}", module);
xmlMapper.registerModules(module);
}
}
if (moduleClassNames != null) {
Iterable<Object> it = ObjectHelper.createIterable(moduleClassNames);
for (Object o : it) {
String name = o.toString();
Class<Module> clazz = camelContext.getClassResolver().resolveMandatoryClass(name, Module.class);
Module module = camelContext.getInjector().newInstance(clazz);
LOG.info("Registering module: {} -> {}", name, module);
xmlMapper.registerModule(module);
}
}
if (moduleRefs != null) {
Iterable<Object> it = ObjectHelper.createIterable(moduleRefs);
for (Object o : it) {
String name = o.toString();
if (name.startsWith("#")) {
name = name.substring(1);
}
Module module = CamelContextHelper.mandatoryLookup(camelContext, name, Module.class);
LOG.info("Registering module: {} -> {}", name, module);
xmlMapper.registerModule(module);
}
}
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project oap by oaplatform.
the class Binder method initialize.
private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion) {
if (mapper instanceof XmlMapper) {
((XmlMapper) mapper).setDefaultUseWrapper(false);
}
AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
mapper.getDeserializationConfig().with(introspector);
mapper.getSerializationConfig().with(introspector);
mapper.registerModule(new AfterburnerModule());
mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
mapper.registerModule(new JodaModule());
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
if (!nonNullInclusion)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
modules.forEach(mapper::registerModule);
if (defaultTyping)
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
return mapper;
}
Aggregations