Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
deserialize(obj: any, targetType: any, baseType?: any, options: IConverterOptions = {}): any {
const {ignoreCallback, checkRequiredValue = true} = options;
try {
if (ignoreCallback && ignoreCallback(obj, targetType, baseType)) {
return obj;
}
if (targetType !== Boolean && (isEmpty(obj) || isEmpty(targetType) || targetType === Object)) {
return obj;
}
const converter = this.getConverter(targetType);
const deserializer: IDeserializer = (o: any, targetType: any, baseType: any) => this.deserialize(o, targetType, baseType, options);
if (converter) {
// deserialize from a custom JsonConverter
return converter!.deserialize!(obj, targetType, baseType, deserializer);
}
/* istanbul ignore next */
if (isArrayOrArrayClass(obj)) {
const converter = this.getConverter(Array);
return converter!.deserialize!(obj, Array, baseType, deserializer);
serialize(obj: any, options: IConverterOptions = {}): any {
try {
if (isEmpty(obj)) {
return obj;
}
const converter = this.getConverter(obj);
const serializer: ISerializer = (o: any, opt?: any) => this.serialize(o, Object.assign({}, options, opt));
if (converter && converter.serialize) {
// deserialize from a custom JsonConverter
return converter.serialize(obj, serializer);
}
if (typeof obj.serialize === "function") {
// deserialize from serialize method
return obj.serialize(options, this);
}
it("should return false when {} is given", () => {
expect(isEmpty({})).to.eq(false);
});
it("should return false when [] is given", () => {
it("should return true when null is given", () => {
expect(isEmpty(null)).to.eq(true);
});
it("should return false when false is given", () => {
expect(isEmpty(false)).to.eq(false);
});
});
it("should return true when empty string is given", () => {
expect(isEmpty("")).to.eq(true);
});
it("should return true when null is given", () => {
it("should return true when empty string is given", () => {
expect(isEmpty(undefined)).to.eq(true);
});
it("should return false when {} is given", () => {