OpenSlides/client/src/app/shared/models/base/deserializer.ts
FinnStutzenstein 1ee76de417 Handling of titles, projection and content objects in items
Restructure the titles for motion, motion-block, assignment and topic.
Less possibilities for more clear code. Added mote base models enabling
functionalities of projection and being a content object for items
2018-09-14 08:36:35 +02:00

39 lines
1.1 KiB
TypeScript

import { Deserializable } from './deserializable';
/**
* Abstract base class for a basic implementation of Deserializable.
* The constructor also gives the possibility to give data that should be serialized.
*/
export abstract class Deserializer implements Deserializable {
/**
* Basic constructor with the possibility to give data to deserialize.
* @param input If data is given, {@method deserialize} will be called with that data
*/
protected constructor(input?: any) {
if (input) {
this.changeNullValuesToUndef(input);
this.deserialize(input);
}
}
/**
* should be used to assign JSON values to the object itself.
* @param input
*/
public deserialize(input: any): void {
Object.assign(this, input);
}
/**
* Prevent to send literally "null" if should be send
* @param input object to deserialize
*/
public changeNullValuesToUndef(input: any): void {
Object.keys(input).forEach(key => {
if (input[key] === null) {
input[key] = undefined;
}
});
}
}