Class BaseMapperOperator
- All Implemented Interfaces:
CodecRegistry,EntityLoader,EntitySaver,MapperOperatorContract
- Direct Known Subclasses:
DefaultMapperOperator
MapperOperatorContract that handles codec
registration and provides core logic for entity serialization and deserialization.
* Note: This is an experimental feature and is currently considered unstable.
This class facilitates the conversion between domain entities and flattened memory
structures by orchestrating the interaction between CodecAdapter and
MapStructureUtils.
The class uses a thread-safe registry to store codecs and supports polymorphic codec lookups using type compatibility checks.
- Since:
- 0.3
- Author:
- a8kj7sea
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> CodecAdapter<T, Map<String, Object>> Attempts to find a suitable codec for the specified class type.<T> Optional<T> load(DataMemory<String> memory, String path, Class<T> type) Loads and reconstructs an entity from the providedDataMemorybased on a specific path.<T> voidregisterCodec(Class<T> type, CodecAdapter<T, Map<String, Object>> codec) Registers a codec for a specific class type.<T> voidsave(DataMemory<String> memory, String path, T entity) Serializes and saves an entity into the providedDataMemoryunder a specific path.
-
Constructor Details
-
BaseMapperOperator
public BaseMapperOperator()
-
-
Method Details
-
registerCodec
Registers a codec for a specific class type.Once registered, the mapping system will use this codec whenever it encounters the specified type during serialization (saving) or deserialization (loading).
Registers a codec in the internal thread-safe map for future use in load/save operations.
- Specified by:
registerCodecin interfaceCodecRegistry- Type Parameters:
T- the domain object type.- Parameters:
type- the class literal of the type to associate with the codec.codec- theCodecAdaptercontaining the serialization and deserialization logic.
-
findCodec
Attempts to find a suitable codec for the specified class type.This method searches for a codec registered for the exact type or a supertype (via
Class.isAssignableFrom(Class)).- Type Parameters:
T- the entity type.- Parameters:
type- the class literal to lookup.- Returns:
- the associated
CodecAdapter, ornullif no compatible codec is registered.
-
load
Loads and reconstructs an entity from the providedDataMemorybased on a specific path.This implementation unflattens the data from the memory into a Map structure before passing it to the appropriate codec for deserialization.
- Specified by:
loadin interfaceEntityLoader- Type Parameters:
T- the expected type of the reconstructed entity.- Parameters:
memory- the source memory implementation containing the flattened data.path- the base configuration path (e.g., "database.mysql") where the entity's data is stored.type- the class literal of the entity to be reconstructed.- Returns:
- an
Optionalcontaining the reconstructed entity, orOptional.empty()if the data is missing or incompatible.
-
save
Serializes and saves an entity into the providedDataMemoryunder a specific path.This implementation serializes the entity into a Map using its registered codec and then flattens that Map into the provided memory at the specified path.
- Specified by:
savein interfaceEntitySaver- Type Parameters:
T- the type of the entity being saved.- Parameters:
memory- the target memory implementation where data will be stored.path- the base configuration path (e.g., "database.mysql") under which the entity's fields will be flattened.entity- the domain object instance to persist.
-