Class JsonToObjectTransformer
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.transformer.AbstractTransformer
org.springframework.integration.json.JsonToObjectTransformer
- All Implemented Interfaces:
- Aware,- BeanClassLoaderAware,- BeanFactoryAware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- ExpressionCapable,- GenericTransformer<Message<?>,,- Message<?>> - NamedComponent,- Transformer
Transformer implementation that converts a JSON string payload into an instance of the
 provided target Class. By default this transformer uses
 JsonObjectMapperProvider
 factory to get an instance of Jackson JSON-processor
 if jackson-databind lib is present on the classpath. Any other JsonObjectMapper
 implementation can be provided.
 
 Since version 3.0, you can omit the target class and the target type can be
 determined by the JsonHeaders type entries - including the contents of a
 one-level container or map type.
 
The type headers can be classes or fully-qualified class names.
 Since version 5.2.6, a SpEL expression option is provided to let to build a target
ResolvableType somehow externally.
- Since:
- 2.0
- Author:
- Mark Fisher, Artem Bilan
- See Also:
- 
Field SummaryFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, logger
- 
Constructor SummaryConstructorsConstructorDescriptionJsonToObjectTransformer(Class<?> targetClass) JsonToObjectTransformer(Class<?> targetClass, JsonObjectMapper<?, ?> jsonObjectMapper) JsonToObjectTransformer(ResolvableType targetType) Construct an instance based on the providedResolvableType.JsonToObjectTransformer(ResolvableType targetType, JsonObjectMapper<?, ?> jsonObjectMapper) Construct an instance based on the providedResolvableTypeandJsonObjectMapper.JsonToObjectTransformer(JsonObjectMapper<?, ?> jsonObjectMapper) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected ObjectdoTransform(Message<?> message) Subclasses must implement this method to provide the transformation logic.Subclasses may implement this method to provide component type information.protected voidonInit()Subclasses may implement this for initialization logic.voidsetBeanClassLoader(ClassLoader classLoader) voidsetValueTypeExpression(Expression valueTypeExpression) Configure a SpELExpressionto evaluate aResolvableTypeto instantiate the payload from the incoming JSON.voidsetValueTypeExpressionString(String valueTypeExpressionString) Configure a SpEL expression to evaluate aResolvableTypeto instantiate the payload from the incoming JSON.Methods inherited from class org.springframework.integration.transformer.AbstractTransformertransformMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
- 
Constructor Details- 
JsonToObjectTransformerpublic JsonToObjectTransformer()
- 
JsonToObjectTransformer
- 
JsonToObjectTransformerConstruct an instance based on the providedResolvableType.- Parameters:
- targetType- the- ResolvableTypeto use.
- Since:
- 5.2
 
- 
JsonToObjectTransformer
- 
JsonToObjectTransformerpublic JsonToObjectTransformer(@Nullable Class<?> targetClass, @Nullable JsonObjectMapper<?, ?> jsonObjectMapper) 
- 
JsonToObjectTransformerpublic JsonToObjectTransformer(ResolvableType targetType, @Nullable JsonObjectMapper<?, ?> jsonObjectMapper) Construct an instance based on the providedResolvableTypeandJsonObjectMapper.- Parameters:
- targetType- the- ResolvableTypeto use.
- jsonObjectMapper- the- JsonObjectMapperto use.
- Since:
- 5.2
 
 
- 
- 
Method Details- 
setBeanClassLoader- Specified by:
- setBeanClassLoaderin interface- BeanClassLoaderAware
 
- 
setValueTypeExpressionStringConfigure a SpEL expression to evaluate aResolvableTypeto instantiate the payload from the incoming JSON. By default this transformer consultsJsonHeadersin the request message. If this expression returnsnullorResolvableTypebuilding throws aClassNotFoundException, this transformer falls back to the providedtargetType. This logic is present as an expression becauseJsonHeadersmay not have real class values, but rather some type ids which have to be mapped to target classes according some external registry.- Parameters:
- valueTypeExpressionString- the SpEL expression to use.
- Since:
- 5.2.6
 
- 
setValueTypeExpressionConfigure a SpELExpressionto evaluate aResolvableTypeto instantiate the payload from the incoming JSON. By default this transformer consultsJsonHeadersin the request message. If this expression returnsnullorResolvableTypebuilding throws aClassNotFoundException, this transformer falls back to the providedtargetType. This logic is present as an expression becauseJsonHeadersmay not have real class values, but rather some type ids which have to be mapped to target classes according some external registry.- Parameters:
- valueTypeExpression- the SpEL- Expressionto use.
- Since:
- 5.2.6
 
- 
getComponentTypeDescription copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
- getComponentTypein interface- NamedComponent
- Overrides:
- getComponentTypein class- IntegrationObjectSupport
 
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- IntegrationObjectSupport
 
- 
doTransformDescription copied from class:AbstractTransformerSubclasses must implement this method to provide the transformation logic. If the return value is itself a Message, it will be used as the result. Otherwise, any non-null return value will be used as the payload of the result Message.- Specified by:
- doTransformin class- AbstractTransformer
- Parameters:
- message- The message.
- Returns:
- The result of the transformation.
 
 
-