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 baseD
- JSON implementation used (JavaScriptObject for client, ObjectNode for server)
- Direct Known Subclasses:
ClientPolymorphicMapper
,InstructionMapper
,PageMapper
,PageSegmentHandleMapper
,ServerPolymorphicMapper
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionextractClass
(T object) boolean
isClassRegistered
(Class<?> clazz) mapFromDTO
(String type, D payload) void
registerIgnore
(Class<?> clazz) Registers a class that should not be serializedvoid
registerMapping
(String type, Class<? extends T> clazz, Mapping<T, D> toDTOMapping, Mapping<D, T> fromDTOMapping)
-
Field Details
-
ignoreList
-
-
Constructor Details
-
PolymorphicMapper
public PolymorphicMapper()
-
-
Method Details
-
registerIgnore
Registers a class that should not be serialized- Parameters:
clazz
- the Class to ignore
-
isClassRegistered
-
extractClass
-
mapToDTO
-
getType
-
mapFromDTO