(data: any, type: string, format: string)
| 337 | } |
| 338 | |
| 339 | public static deserialize(data: any, type: string, format: string) { |
| 340 | // polymorphism may change the actual type. |
| 341 | type = ObjectSerializer.findCorrectType(data, type); |
| 342 | if (data == undefined) { |
| 343 | return data; |
| 344 | } else if (primitives.indexOf(type.toLowerCase()) !== -1) { |
| 345 | return data; |
| 346 | } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 |
| 347 | let subType: string = type.replace("Array<", ""); // Array<Type> => Type> |
| 348 | subType = subType.substring(0, subType.length - 1); // Type> => Type |
| 349 | let transformedData: any[] = []; |
| 350 | for (let index in data) { |
| 351 | let date = data[index]; |
| 352 | transformedData.push(ObjectSerializer.deserialize(date, subType, format)); |
| 353 | } |
| 354 | return transformedData; |
| 355 | } else if (type === "Date") { |
| 356 | return new Date(data); |
| 357 | } else { |
| 358 | if (enumsMap.has(type)) {// is Enum |
| 359 | return data; |
| 360 | } |
| 361 | |
| 362 | if (!typeMap[type]) { // dont know the type |
| 363 | return data; |
| 364 | } |
| 365 | let instance = new typeMap[type](); |
| 366 | let attributeTypes = typeMap[type].getAttributeTypeMap(); |
| 367 | for (let index in attributeTypes) { |
| 368 | let attributeType = attributeTypes[index]; |
| 369 | let value = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format); |
| 370 | if (value !== undefined) { |
| 371 | instance[attributeType.name] = value; |
| 372 | } |
| 373 | } |
| 374 | return instance; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /** |
no test coverage detected