Skip to content

Commit a5969c3

Browse files
[TASKSCLOUD-278] - Enhanced serializer method for proper serialize date as single value in request body.
1 parent b769552 commit a5969c3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/internal/objectSerializer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ObjectSerializer {
4242
/**
4343
* Serilize object to json string.
4444
*/
45-
public static serialize(data: any, type: string) {
45+
public static serialize(data: any, type: string, isRecursiveCall :boolean = false) {
4646
if (data === undefined) {
4747
return data;
4848
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
@@ -54,12 +54,13 @@ export class ObjectSerializer {
5454
for (const index in data) {
5555
if (data.hasOwnProperty(index)) {
5656
const date = data[index];
57-
transformedData.push(ObjectSerializer.serialize(date, subType));
57+
transformedData.push(ObjectSerializer.serialize(date, subType, true));
5858
}
5959
}
6060
return transformedData;
6161
} else if (type === "Date") {
62-
return new Date(data);
62+
const result = data.toISOString() as string;
63+
return isRecursiveCall ? result : "\"" + result + "\"";;
6364
} else {
6465
if (enumsMap[type]) {
6566
return data;
@@ -74,7 +75,7 @@ export class ObjectSerializer {
7475
for (const index in attributeTypes) {
7576
if (attributeTypes.hasOwnProperty(index)) {
7677
const attributeType = attributeTypes[index];
77-
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
78+
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, true);
7879
}
7980
}
8081
return instance;

0 commit comments

Comments
 (0)