Spring Integration

org.springframework.integration.transformer
Class ObjectToMapTransformer

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.transformer.AbstractTransformer
          extended by org.springframework.integration.transformer.AbstractPayloadTransformer<java.lang.Object,java.util.Map<?,?>>
              extended by org.springframework.integration.transformer.ObjectToMapTransformer
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, NamedComponent, Transformer

public class ObjectToMapTransformer
extends AbstractPayloadTransformer<java.lang.Object,java.util.Map<?,?>>

Will transform 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 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.
public class Person { public String name = "John"; public Address address = new Address(); } public class Address { private String street = "123 Main Street"; } The resulting Map would look like this: {name=John, address.street=123 Main Street}

Since:
2.0
Author:
Oleg Zhurakousky

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
ObjectToMapTransformer()
           
 
Method Summary
 void setShouldFlattenKeys(boolean shouldFlattenKeys)
           
protected  java.util.Map<java.lang.String,java.lang.Object> transformPayload(java.lang.Object payload)
           
 
Methods inherited from class org.springframework.integration.transformer.AbstractPayloadTransformer
doTransform
 
Methods inherited from class org.springframework.integration.transformer.AbstractTransformer
transform
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getComponentType, getConversionService, getTaskScheduler, onInit, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectToMapTransformer

public ObjectToMapTransformer()
Method Detail

setShouldFlattenKeys

public void setShouldFlattenKeys(boolean shouldFlattenKeys)

transformPayload

protected java.util.Map<java.lang.String,java.lang.Object> transformPayload(java.lang.Object payload)
                                                                     throws java.lang.Exception
Specified by:
transformPayload in class AbstractPayloadTransformer<java.lang.Object,java.util.Map<?,?>>
Throws:
java.lang.Exception

Spring Integration