Class PolymorphicMapper<T,D>

java.lang.Object
com.levigo.jadice.web.transport.shared.messaging.PolymorphicMapper<T,D>
Type Parameters:
T - Interface or abstract class used as a semantical base
D - JSON implementation used (JavaScriptObject for client, ObjectNode for server)
Direct Known Subclasses:
ClientPolymorphicMapper, InstructionMapper, PageMapper, PageSegmentHandleMapper, ServerPolymorphicMapper

public abstract class PolymorphicMapper<T,D> extends Object
This class solves the problem of managing class hierarchies when mapping objects to DTOs and can be extended for any given base class. In the future, messages will be sent from and received in the frontend in pure JS/TS, which does not allow us to use shared classes anymore. Also, many of the complex structures can be represented far simpler in JSON without requiring class hierarchies at all. e.g. {type: "URL", url: "https://[...].pdf"} as an equivalent to a "UrlSource" class, extending from Source. Therefore, we want an independent DTO mapping. While this might seem redundant as long as we are working with GWT, there will be no need for such a process in the frontend in the long term - this is just glue code to allow the deprecated GWT webtoolkit to interface seamlessly with the new API. TODO: Update this comment as soon as GWT is fully gone. :)
  • Field Details

    • ignoreList

      protected final List<String> ignoreList
  • Constructor Details

    • PolymorphicMapper

      public PolymorphicMapper()
  • Method Details

    • registerMapping

      public void registerMapping(String type, Class<? extends T> clazz, Mapping<T,D> toDTOMapping, Mapping<D,T> fromDTOMapping)
    • registerIgnore

      public void registerIgnore(Class<?> clazz)
      Registers a class that should not be serialized
      Parameters:
      clazz - the Class to ignore
    • isClassRegistered

      public boolean isClassRegistered(Class<?> clazz)
    • extractClass

      protected Class<? extends T> extractClass(T object)
    • mapToDTO

      public D mapToDTO(T object)
    • getType

      public String getType(T object)
    • mapFromDTO

      public T mapFromDTO(String type, D payload)