Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (36 sloc) 937 Bytes
import {Converter} from "../decorators/converter";
import {IConverter, IDeserializer, ISerializer} from "../interfaces/index";
/**
* Converter component for the `Map` Type.
* @private
* @converters
* @component
*/
@Converter(Map)
export class MapConverter implements IConverter {
/**
*
* @param data
* @param target
* @param baseType
* @param deserializer
* @returns {Map<string, T>}
*/
deserialize<T>(data: any, target: any, baseType: T, deserializer: IDeserializer): Map<string, T> {
const obj = new Map<string, T>();
Object.keys(data).forEach(key => {
obj.set(key, deserializer(data[key], baseType) as T);
});
return obj;
}
/**
*
* @param data
* @param serializer
*/
serialize<T>(data: Map<string, T>, serializer: ISerializer): any {
const obj: any = {};
data.forEach((value: T, key: string) => (obj[key] = serializer(value)));
return obj;
}
}
You can’t perform that action at this time.