Skip to content

Commit f09d6ba

Browse files
feat: add deprecation notice to some functions
1 parent 6c2f8ce commit f09d6ba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export function plainToClass<T, V>(cls: ClassConstructor<T>, plain: V | V[], opt
5757
* Converts plain (literal) object to class (constructor) object.
5858
* Uses given object as source object (it means fills given object with data from plain object).
5959
* Also works with arrays.
60+
*
61+
* @deprecated This function is being removed. The current implementation is incorrect as it modifies the source object.
6062
*/
6163
export function plainToClassFromExist<T, V>(clsObject: T[], plain: V[], options?: ClassTransformOptions): T[];
6264
export function plainToClassFromExist<T, V>(clsObject: T, plain: V, options?: ClassTransformOptions): T;
@@ -77,6 +79,8 @@ export function classToClass<T>(object: T | T[], options?: ClassTransformOptions
7779
* Converts class (constructor) object to plain (literal) object.
7880
* Uses given plain object as source object (it means fills given plain object with data from class object).
7981
* Also works with arrays.
82+
*
83+
* @deprecated This function is being removed. The current implementation is incorrect as it modifies the source object.
8084
*/
8185
export function classToClassFromExist<T>(object: T, fromObject: T, options?: ClassTransformOptions): T;
8286
export function classToClassFromExist<T>(object: T, fromObjects: T[], options?: ClassTransformOptions): T[];
@@ -86,6 +90,11 @@ export function classToClassFromExist<T>(object: T, fromObject: T | T[], options
8690

8791
/**
8892
* Serializes given object to a JSON string.
93+
*
94+
* @deprecated This function is being removed. Please use
95+
* ```
96+
* JSON.stringify(classToPlain(object, options))
97+
* ```
8998
*/
9099
export function serialize<T>(object: T, options?: ClassTransformOptions): string;
91100
export function serialize<T>(object: T[], options?: ClassTransformOptions): string;
@@ -95,13 +104,24 @@ export function serialize<T>(object: T | T[], options?: ClassTransformOptions):
95104

96105
/**
97106
* Deserializes given JSON string to a object of the given class.
107+
*
108+
* @deprecated This function is being removed. Please use the following instead:
109+
* ```
110+
* plainToClass(cls, JSON.parse(json), options)
111+
* ```
98112
*/
99113
export function deserialize<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T {
100114
return classTransformer.deserialize(cls, json, options);
101115
}
102116

103117
/**
104118
* Deserializes given JSON string to an array of objects of the given class.
119+
*
120+
* @deprecated This function is being removed. Please use the following instead:
121+
* ```
122+
* JSON.parse(json).map(value => plainToClass(cls, value, options))
123+
* ```
124+
*
105125
*/
106126
export function deserializeArray<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T[] {
107127
return classTransformer.deserializeArray(cls, json, options);

0 commit comments

Comments
 (0)