UNPKG

@ima/plugin-http-client

Version:

Generic http client for the IMA application framework.

30 lines (29 loc) 881 B
import { BaseMapper } from './BaseMapper'; import { BaseEntity } from '../BaseEntity'; /** * EntityMapper transform object into entity property which is instance of BaseEntity. */ export class EntityMapper extends BaseMapper { #EntityClass; /** * Creates a mapper with the specified entity that is used for the transformation field. * @param entity */ constructor(entity){ super(); this.#EntityClass = entity; } deserialize(data) { if (!data || typeof data === 'string' || data instanceof BaseEntity) { return data; } return Reflect.construct(this.#EntityClass, [ data ]); } serialize(entity) { if (!entity || !(entity instanceof BaseEntity)) { return entity; } return entity.serialize(); } } //# sourceMappingURL=EntityMapper.js.map