* Serializes provided value. * * @param {TypeLike >} x Some value. * @param {SerializerContext >} serializerContext Serializer context. * * @returns {TypeLike } Serialized value or undefined.
(x: TypeLike<Array<any>>, serializerContext: SerializerContext<Array<any>>)
| 18 | * @returns {TypeLike<any>} Serialized value or undefined. |
| 19 | */ |
| 20 | public serialize(x: TypeLike<Array<any>>, serializerContext: SerializerContext<Array<any>>): TypeLike<any> |
| 21 | { |
| 22 | if (x === undefined) |
| 23 | { |
| 24 | return serializerContext.serializedDefaultValue; |
| 25 | } |
| 26 | |
| 27 | if (x === null) |
| 28 | { |
| 29 | return serializerContext.serializedNullValue; |
| 30 | } |
| 31 | |
| 32 | if (Array.isArray(x)) |
| 33 | { |
| 34 | return serializerContext.defineReference(x, () => |
| 35 | { |
| 36 | const arrayInput = x; |
| 37 | const arrayOutput = new Array<any>(x.length); |
| 38 | const genericSerializerContext = serializerContext.defineGenericSerializerContext(0); |
| 39 | const valueSerializerContext = genericSerializerContext.defineChildSerializerContext(); |
| 40 | const serializer = valueSerializerContext.serializer; |
| 41 | |
| 42 | valueSerializerContext.referenceValueSetter = (v, k) => arrayOutput[k] = v; |
| 43 | |
| 44 | for (let i = 0; i < arrayInput.length; i++) |
| 45 | { |
| 46 | valueSerializerContext.jsonPathKey = i; |
| 47 | |
| 48 | arrayOutput[i] = serializer.serialize(arrayInput[i], valueSerializerContext); |
| 49 | } |
| 50 | |
| 51 | return arrayOutput; |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | serializerContext.logger.error('ArraySerializer', `${serializerContext.jsonPath}: cannot serialize value as array.`, x); |
| 56 | |
| 57 | return undefined; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Deserializes provided value. |
nothing calls this directly
no test coverage detected