public class JsonToObjectTransformer extends AbstractTransformer implements org.springframework.beans.factory.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,
ResolvableTypeEXPRESSION_PARSER, logger| Constructor and Description |
|---|
JsonToObjectTransformer() |
JsonToObjectTransformer(java.lang.Class<?> targetClass) |
JsonToObjectTransformer(java.lang.Class<?> targetClass,
JsonObjectMapper<?,?> jsonObjectMapper) |
JsonToObjectTransformer(JsonObjectMapper<?,?> jsonObjectMapper) |
JsonToObjectTransformer(org.springframework.core.ResolvableType targetType)
Construct an instance based on the provided
ResolvableType. |
JsonToObjectTransformer(org.springframework.core.ResolvableType targetType,
JsonObjectMapper<?,?> jsonObjectMapper)
Construct an instance based on the provided
ResolvableType and JsonObjectMapper. |
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
doTransform(org.springframework.messaging.Message<?> message)
Subclasses must implement this method to provide the transformation
logic.
|
java.lang.String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
void |
setBeanClassLoader(java.lang.ClassLoader classLoader) |
void |
setValueTypeExpression(org.springframework.expression.Expression valueTypeExpression)
Configure a SpEL
Expression to evaluate a ResolvableType
to instantiate the payload from the incoming JSON. |
void |
setValueTypeExpressionString(java.lang.String valueTypeExpressionString)
Configure a SpEL expression to evaluate a
ResolvableType
to instantiate the payload from the incoming JSON. |
transformafterPropertiesSet, 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, toStringpublic JsonToObjectTransformer()
public JsonToObjectTransformer(@Nullable
java.lang.Class<?> targetClass)
public JsonToObjectTransformer(org.springframework.core.ResolvableType targetType)
ResolvableType.targetType - the ResolvableType to use.public JsonToObjectTransformer(@Nullable
JsonObjectMapper<?,?> jsonObjectMapper)
public JsonToObjectTransformer(@Nullable
java.lang.Class<?> targetClass,
@Nullable
JsonObjectMapper<?,?> jsonObjectMapper)
public JsonToObjectTransformer(org.springframework.core.ResolvableType targetType,
@Nullable
JsonObjectMapper<?,?> jsonObjectMapper)
ResolvableType and JsonObjectMapper.targetType - the ResolvableType to use.jsonObjectMapper - the JsonObjectMapper to use.public void setBeanClassLoader(java.lang.ClassLoader classLoader)
setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAwarepublic void setValueTypeExpressionString(java.lang.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(org.springframework.expression.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 java.lang.String getComponentType()
IntegrationObjectSupportgetComponentType in interface NamedComponentgetComponentType in class IntegrationObjectSupportprotected void onInit()
IntegrationObjectSupportonInit in class IntegrationObjectSupportprotected java.lang.Object doTransform(org.springframework.messaging.Message<?> message)
AbstractTransformerdoTransform in class AbstractTransformermessage - The message.