MCPcopy Create free account
hub / github.com/dipscope/TypeManager.TS / serialize

Method serialize

src/serializers/string-serializer.ts:20–45  ·  view source on GitHub ↗

* Serializes provided value. * * @param {TypeLike } x Some value. * @param {SerializerContext } serializerContext Serializer context. * * @returns {TypeLike } Serialized value or undefined.

(x: TypeLike<string>, serializerContext: SerializerContext<string>)

Source from the content-addressed store, hash-verified

18 * @returns {TypeLike<any>} Serialized value or undefined.
19 */
20 public serialize(x: TypeLike<string>, serializerContext: SerializerContext<string>): 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 (typeof x === 'string')
33 {
34 return x;
35 }
36
37 if (serializerContext.useImplicitConversion)
38 {
39 return this.convert(x, serializerContext);
40 }
41
42 serializerContext.logger.error('StringSerializer', `${serializerContext.jsonPath}: cannot serialize value as string.`, x);
43
44 return undefined;
45 }
46
47 /**
48 * Deserializes provided value.

Callers

nothing calls this directly

Calls 2

convertMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected