Class DefaultClassMapper

All Implemented Interfaces:
ClassMapper, InitializingBean

public class DefaultClassMapper extends Object implements ClassMapper, InitializingBean
Maps to/from JSON using type information in the MessageProperties; the default name of the message property containing the type is "__TypeId__". An optional property setDefaultType(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, call afterPropertiesSet() to set up the class to id mapping.
Mark Pollack, Gary Russell, Artem Bilan
  • Field Details

  • Constructor Details

    • DefaultClassMapper

      public DefaultClassMapper()
  • Method Details

    • setDefaultType

      public void setDefaultType(Class<?> defaultType)
      The type returned by toClass(MessageProperties) if no type information is found in the message properties.
      defaultType - the defaultType to set.
    • setDefaultMapClass

      public void setDefaultMapClass(Class<?> defaultMapClass)
      Set the type of Map to use. For outbound messages, set the "__TypeId__" header to HashTable. For inbound messages, if the "__TypeId__" header is Hashtable convert to this class.
      defaultMapClass - the map class.
      See Also:
    • getClassIdFieldName

      public String getClassIdFieldName()
      The name of the header that contains the type id.
      See Also:
    • setIdClassMapping

      public void setIdClassMapping(Map<String,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.
      idClassMapping - the map of IDs to classes.
    • setTrustedPackages

      public void setTrustedPackages(@Nullable String... trustedPackages)
      Specify a set of packages to trust during deserialization. The asterisk (*) means trust all.
      trustedPackages - the trusted Java packages for deserialization
    • afterPropertiesSet

      public void afterPropertiesSet()

      Creates the reverse mapping from class to type id.

      Specified by:
      afterPropertiesSet in interface InitializingBean
    • fromClass

      public void fromClass(Class<?> clazz, MessageProperties properties)
      Specified by:
      fromClass in interface ClassMapper
    • toClass

      public Class<?> toClass(MessageProperties properties)
      Specified by:
      toClass in interface ClassMapper