Class DefaultClassMapper
- java.lang.Object
-
- org.springframework.amqp.support.converter.DefaultClassMapper
-
- All Implemented Interfaces:
ClassMapper,org.springframework.beans.factory.InitializingBean
public class DefaultClassMapper extends java.lang.Object implements ClassMapper, org.springframework.beans.factory.InitializingBean
Maps to/from JSON using type information in theMessageProperties; the default name of the message property containing the type is "__TypeId__". An optional propertysetDefaultType(Class)is provided that allows mapping to a statically defined type, if no message property is found in the message properties.setIdClassMapping(Map)can be used to map tokens in the "__TypeId__" header to classes. If this class is not a Spring-managed bean, callafterPropertiesSet()to set up the class to id mapping.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_CLASSID_FIELD_NAME
-
Constructor Summary
Constructors Constructor Description DefaultClassMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()voidfromClass(java.lang.Class<?> clazz, MessageProperties properties)java.lang.StringgetClassIdFieldName()The name of the header that contains the type id.voidsetDefaultMapClass(java.lang.Class<?> defaultMapClass)Set the type ofMapto use.voidsetDefaultType(java.lang.Class<?> defaultType)The type returned bytoClass(MessageProperties)if no type information is found in the message properties.voidsetIdClassMapping(java.util.Map<java.lang.String,java.lang.Class<?>> idClassMapping)Set a map of type Ids (in the "__TypeId__" header) to classes.voidsetTrustedPackages(java.lang.String... trustedPackages)Specify a set of packages to trust during deserialization.java.lang.Class<?>toClass(MessageProperties properties)
-
-
-
Field Detail
-
DEFAULT_CLASSID_FIELD_NAME
public static final java.lang.String DEFAULT_CLASSID_FIELD_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
setDefaultType
public void setDefaultType(java.lang.Class<?> defaultType)
The type returned bytoClass(MessageProperties)if no type information is found in the message properties.- Parameters:
defaultType- the defaultType to set.
-
setDefaultMapClass
public void setDefaultMapClass(java.lang.Class<?> defaultMapClass)
Set the type ofMapto use. For outbound messages, set the "__TypeId__" header toHashTable. For inbound messages, if the "__TypeId__" header isHashtableconvert to this class.- Parameters:
defaultMapClass- the map class.- Since:
- 2.0
- See Also:
DEFAULT_CLASSID_FIELD_NAME
-
getClassIdFieldName
public java.lang.String getClassIdFieldName()
The name of the header that contains the type id.- Returns:
- "__TypeId__"
- See Also:
DEFAULT_CLASSID_FIELD_NAME
-
setIdClassMapping
public void setIdClassMapping(java.util.Map<java.lang.String,java.lang.Class<?>> idClassMapping)
Set a map of type Ids (in the "__TypeId__" header) to classes. For outbound messages, if the class is not in this map, the "__TypeId__" header is set to the fully qualified class name.- Parameters:
idClassMapping- the map of IDs to classes.
-
setTrustedPackages
public void setTrustedPackages(@Nullable java.lang.String... trustedPackages)Specify a set of packages to trust during deserialization. The asterisk (*) means trust all.- Parameters:
trustedPackages- the trusted Java packages for deserialization- Since:
- 1.6.11
-
afterPropertiesSet
public void afterPropertiesSet()
Creates the reverse mapping from class to type id.
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
fromClass
public void fromClass(java.lang.Class<?> clazz, MessageProperties properties)- Specified by:
fromClassin interfaceClassMapper
-
toClass
public java.lang.Class<?> toClass(MessageProperties properties)
- Specified by:
toClassin interfaceClassMapper
-
-