public class JsonToObjectTransformer extends AbstractTransformer implements BeanClassLoaderAware
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.
JsonObjectMapper
,
JsonObjectMapperProvider
,
ResolvableType
EXPRESSION_PARSER, logger
Constructor and Description |
---|
JsonToObjectTransformer() |
JsonToObjectTransformer(Class<?> targetClass) |
JsonToObjectTransformer(Class<?> targetClass,
JsonObjectMapper<?,?> jsonObjectMapper) |
JsonToObjectTransformer(JsonObjectMapper<?,?> jsonObjectMapper) |
JsonToObjectTransformer(ResolvableType targetType)
Construct an instance based on the provided
ResolvableType . |
JsonToObjectTransformer(ResolvableType targetType,
JsonObjectMapper<?,?> jsonObjectMapper)
Construct an instance based on the provided
ResolvableType and JsonObjectMapper . |
Modifier and Type | Method and Description |
---|---|
protected Object |
doTransform(Message<?> message)
Subclasses must implement this method to provide the transformation
logic.
|
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
void |
setBeanClassLoader(ClassLoader classLoader) |
void |
setValueTypeExpression(Expression valueTypeExpression)
Configure a SpEL
Expression to evaluate a ResolvableType
to instantiate the payload from the incoming JSON. |
void |
setValueTypeExpressionString(String valueTypeExpressionString)
Configure a SpEL expression to evaluate a
ResolvableType
to instantiate the payload from the incoming JSON. |
transform
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
public JsonToObjectTransformer()
public JsonToObjectTransformer(ResolvableType targetType)
ResolvableType
.targetType
- the ResolvableType
to use.public JsonToObjectTransformer(@Nullable JsonObjectMapper<?,?> jsonObjectMapper)
public JsonToObjectTransformer(@Nullable Class<?> targetClass, @Nullable JsonObjectMapper<?,?> jsonObjectMapper)
public JsonToObjectTransformer(ResolvableType targetType, @Nullable JsonObjectMapper<?,?> jsonObjectMapper)
ResolvableType
and JsonObjectMapper
.targetType
- the ResolvableType
to use.jsonObjectMapper
- the JsonObjectMapper
to use.public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
public void setValueTypeExpressionString(String valueTypeExpressionString)
ResolvableType
to instantiate the payload from the incoming JSON.
By default this transformer consults JsonHeaders
in the request message.
If this expression returns null
or ResolvableType
building throws a
ClassNotFoundException
, this transformer falls back to the provided targetType
.
This logic is present as an expression because JsonHeaders
may not have real class values,
but rather some type ids which have to be mapped to target classes according some external registry.valueTypeExpressionString
- the SpEL expression to use.public void setValueTypeExpression(Expression valueTypeExpression)
Expression
to evaluate a ResolvableType
to instantiate the payload from the incoming JSON.
By default this transformer consults JsonHeaders
in the request message.
If this expression returns null
or ResolvableType
building throws a
ClassNotFoundException
, this transformer falls back to the provided targetType
.
This logic is present as an expression because JsonHeaders
may not have real class values,
but rather some type ids which have to be mapped to target classes according some external registry.valueTypeExpression
- the SpEL Expression
to use.public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class IntegrationObjectSupport
protected void onInit()
IntegrationObjectSupport
onInit
in class IntegrationObjectSupport
protected Object doTransform(Message<?> message)
AbstractTransformer
doTransform
in class AbstractTransformer
message
- The message.