class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

fix: Documentation in index.d.ts deprecated functions deserialize, serialize

Open gomixx18 opened this issue 4 years ago • 1 comments

Description

deserialize and serialize functions have an error in documentation requesting to change the function to instanceToClass function which is not defined in the index.d.ts file.

export declare function serialize<T>(object: T, options?: ClassTransformOptions): string;
export declare function serialize<T>(object: T[], options?: ClassTransformOptions): string;
/**
 * Deserializes given JSON string to a object of the given class.
 *
 * @deprecated This function is being removed. Please use the following instead:
 * ```
 * **instanceToClass**(cls, JSON.parse(json), options)
 * ```
 */
export declare function deserialize<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T;
/**
 * Deserializes given JSON string to an array of objects of the given class.
 *
 * @deprecated This function is being removed. Please use the following instead:
 * ```
 * JSON.parse(json).map(value => **instanceToClass**(cls, value, options))
 * ```
 *
 */

not sure what the correct wording is.

gomixx18 avatar Apr 22 '22 08:04 gomixx18

I'm also seeing this.

dessalines avatar Jun 12 '22 17:06 dessalines

I have the same problem:

Steps to reproduce:

  1. Install class-transformer

  2. Try to use it

    import { deserializeArray, deserialize } from 'class-transformer';
    
    class AClass
    {
    	foo: number = 1;
    	bar: string = "baz";
    }
    
    const jsonArrayString: string = '[{"foo": 1, "bar": "baz"}, {"foo": 2, "bar": "qux"}]';
    const deserializedArray: AClass[] = deserializeArray(AClass, jsonArrayString);
    
    const jsonObjectString: string = '{"foo": 3, "bar": "bax"}';
    const deserialized = deserialize(AClass, jsonObjectString);
    
    

Both functions will be reported as deprecated:

obraz

obraz

In fact when searching for 'instanceToClass' inside the codebase, only two occurrences can be found, in the JSdoc comments of deserialize() and deserializeArray() in src/index.ts:

obraz

Also, since the two functions are deprecated, consider removing them from the readme.

l0ner avatar Nov 01 '22 10:11 l0ner

Duplicate of https://github.com/typestack/class-transformer/issues/1019

diffy0712 avatar May 09 '24 21:05 diffy0712