Problem statement
Design the object model and public APIs for an object mapper that copies data between two object shapes — for example a persistence entity and an API DTO — using configured mapping rules, so callers stop hand-writing field-by-field copies.
Operating context. One in-process library. A developer registers a mapping from a source type to a destination type: matching fields by name/convention, renaming fields, ignoring fields, custom field transforms, recursively mapping nested objects, and mapping collections element-by-element. The mapper builds and caches a compiled plan per type pair and applies it to instances. Mappings are registered at startup and applied concurrently at runtime.
Out of scope. The reflection or codegen mechanics of any particular language, JSON/serialization (a separate concern), database ORM hydration, validation of the mapped result, and bidirectional auto-synchronization.
What to produce. The class hierarchy (mapper, type-pair mapping definition, field binding, value converters, the compiled plan), the public APIs, and how a mapping plan is built and applied. Be explicit about: how custom field converters plug in, how nested and collection mappings reuse other registered mappings, and how a missing or ambiguous field mapping is surfaced.
Functional requirements
- Register a mapping between a source type and a destination type, auto-binding fields that match by name.
- Override individual field bindings with renames, ignores, or custom value transforms.
- Map nested objects by delegating to the registered mapping for the nested type pair.
- Map collections element-by-element using the element type's registered mapping.
- Apply a registered mapping to a source instance and produce a populated destination instance.
- Report unmapped required destination fields or an unregistered nested type pair as a configuration error.
Non-functional requirements
- A mapping plan for a type pair is built once and reused; applying it is linear in the number of bound fields.
- Registered mappings are immutable after configuration and safe to apply concurrently.
- New value converters plug in behind one interface without changing the mapping engine.
- Nested and collection mapping reuse existing registered mappings rather than re-specifying them.
- The mapper is unit-testable with plain objects — no ORM, serializer, or framework context.
- Configuration errors are detected at registration/compile time where possible, not silently at apply time.
Topics
- System Design LLD
- Oop Solid
- Patterns Builder
- Patterns Strategy
- Patterns Composite