* Converts provided value to the target type value. * * @param {any} x Some value. * @param {SerializerContext } serializerContext Type serializer context. * * @returns {TypeLike } Converted value or original value.
(x: any, serializerContext: SerializerContext<string>)
| 88 | * @returns {TypeLike<string>} Converted value or original value. |
| 89 | */ |
| 90 | private convert(x: any, serializerContext: SerializerContext<string>): TypeLike<string> |
| 91 | { |
| 92 | if (typeof x === 'number' || typeof x === 'boolean') |
| 93 | { |
| 94 | return String(x); |
| 95 | } |
| 96 | |
| 97 | if (x instanceof Date) |
| 98 | { |
| 99 | return x.toISOString(); |
| 100 | } |
| 101 | |
| 102 | if (typeof x === 'object') |
| 103 | { |
| 104 | return JSON.stringify(x); |
| 105 | } |
| 106 | |
| 107 | serializerContext.logger.error('StringSerializer', `${serializerContext.jsonPath}: cannot convert value to string.`, x); |
| 108 | |
| 109 | return undefined; |
| 110 | } |
| 111 | } |
no test coverage detected