automapper/mikro
Overview
@automapper/mikro
is an official strategy that works with MikroORM. @automapper/mikro
is an extension of @automapper/classes
Installation
npm i @automapper/core @automapper/classes @automapper/mikro
yarn add @automapper/core @automapper/classes @automapper/mikro
Usage
Using @automapper/mikro
isn't different from using @automapper/classes
. The difference is @automapper/mikro
has a custom preMap
that handles how to serialize the sourceObject
because of how MikroORM returns the object upon a Retrieve operation.
preMap
The default preMap
from @automapper/mikro
checks for Collection, Reference, and Entity recursively to serialize the sourceObject
to their raw JSON data.
We can customize this preMap
via MappingStrategyInitializerOptions
const mapper = createMapper({
strategyInitializer: mikro({ preMap: customPreMap }),
});