17 lines
635 B
TypeScript
17 lines
635 B
TypeScript
import { Serializable } from '../models/interfaces/Serializable';
|
|
export class JsonSerializer{
|
|
|
|
public static fromJSONArray<T extends Serializable<T>>(items: any[], type: { new(): T; }): T[] {
|
|
if(!items)return new Array<T>();
|
|
const objectList: T[] = new Array<T>();
|
|
for (let i = 0; i < items.length; i++) {
|
|
objectList.push(new type().fromJSONObject(items[i]))
|
|
}
|
|
return objectList;
|
|
}
|
|
|
|
public static fromJSONObject<T extends Serializable<T>>(item: any, type: { new(): T; }): T {
|
|
if(!item)return null;
|
|
return new type().fromJSONObject(item);
|
|
}
|
|
}
|