diff --git a/build.gradle b/build.gradle
index d88ce6bd92..bb39469ca3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -316,6 +316,7 @@ project('spring-integration-core') {
testCompile ("org.aspectj:aspectjweaver:$aspectjVersion")
testCompile "io.projectreactor:reactor-test:$reactorVersion"
+ testCompile ("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson2Version")
}
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ObjectToMapTransformerParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ObjectToMapTransformerParser.java
index bd2dc3d8ac..9058e06f3d 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ObjectToMapTransformerParser.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ObjectToMapTransformerParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +21,13 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.transformer.ObjectToMapTransformer;
+import org.springframework.util.StringUtils;
/**
* @author Oleg Zhurakousky
* @author Mauro Franceschini
+ * @author Artem Bilan
+ *
* @since 2.0
*/
public class ObjectToMapTransformerParser extends AbstractTransformerParser {
@@ -36,6 +39,11 @@ public class ObjectToMapTransformerParser extends AbstractTransformerParser {
@Override
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
+ String objectMapper = element.getAttribute("object-mapper");
+ if (StringUtils.hasText(objectMapper)) {
+ builder.addConstructorArgReference(objectMapper);
+ }
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "flatten", "shouldFlattenKeys");
}
+
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java
index 77ef35afa7..c136433eea 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/Transformers.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,6 +71,16 @@ public abstract class Transformers {
return transformer;
}
+ public static ObjectToMapTransformer toMap(JsonObjectMapper, ?> jsonObjectMapper) {
+ return new ObjectToMapTransformer(jsonObjectMapper);
+ }
+
+ public static ObjectToMapTransformer toMap(JsonObjectMapper, ?> jsonObjectMapper, boolean shouldFlattenKeys) {
+ ObjectToMapTransformer transformer = new ObjectToMapTransformer();
+ transformer.setShouldFlattenKeys(shouldFlattenKeys);
+ return transformer;
+ }
+
public static MapToObjectTransformer fromMap(Class> targetClass) {
return new MapToObjectTransformer(targetClass);
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java
index ef7e591ab9..6aa6038d17 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2016 the original author or authors.
+ * Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,9 +44,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*
*
{@link MapperFeature#DEFAULT_VIEW_INCLUSION} is disabled
*
{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled
+ *
{@link ObjectMapper#findAndRegisterModules()} is performed
*
*
* @author Artem Bilan
+ * @author Vikas Prasad
+ *
* @since 3.0
*/
public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper {
@@ -57,6 +60,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper
+ * Transforms an object graph into a Map. It supports a conventional Map (map of maps)
+ * where complex attributes are represented as Map values as well as a flat Map
+ * where keys document the path to the value. By default it will transform to a flat Map.
+ * If you need to transform to a Map of Maps set the 'shouldFlattenKeys' property to 'false'
+ * via the {@link ObjectToMapTransformer#setShouldFlattenKeys(boolean)} method.
+ * It supports Collections, Maps and Arrays which means that for flat maps it will flatten
+ * an Object's properties. Below is an example showing how a flattened
+ * Object hierarchy is represented when 'shouldFlattenKeys' is TRUE.
+ *
+ * The transformation is based on to and then from JSON conversion.
*
*
* public class Person {
@@ -52,14 +57,36 @@ import org.springframework.util.StringUtils;
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Gary Russell
+ * @author Vikas Prasad
+ *
* @since 2.0
+ *
+ * @see JsonObjectMapperProvider
*/
public class ObjectToMapTransformer extends AbstractPayloadTransformer