deserialize()

in packages/@jsii/kernel/src/serialization.ts [767:843]


    deserialize(value, _type, host) {
      if (value == null) {
        return undefined;
      }

      if (isWireDate(value)) {
        host.debug('ANY is a Date');
        return deserializeDate(value);
      }
      if (isScalar(value)) {
        host.debug('ANY is a Scalar');
        return value;
      }
      if (Array.isArray(value)) {
        host.debug('ANY is an Array');
        return value.map((e, idx) =>
          process(
            host,
            'deserialize',
            e,
            { type: spec.CANONICAL_ANY },
            `index ${inspect(idx)}`,
          ),
        );
      }

      if (isWireEnum(value)) {
        host.debug('ANY is an Enum');
        return deserializeEnum(value, host);
      }
      if (isWireMap(value)) {
        host.debug('ANY is a Map');
        const mapOfAny: spec.CollectionTypeReference = {
          collection: {
            kind: spec.CollectionKind.Map,
            elementtype: spec.CANONICAL_ANY,
          },
        };
        return SERIALIZERS[SerializationClass.Map].deserialize(
          value,
          { type: mapOfAny },
          host,
        );
      }
      if (isObjRef(value)) {
        host.debug('ANY is a Ref');
        return host.objects.findObject(value).instance;
      }

      // if the value has a struct token, it was serialized by a typed jsii
      // struct, but since the deserialization target is ANY, all we can do is
      // strip the data from $jsii.struct and continue to deserialize as ANY.
      if (isWireStruct(value)) {
        const { fqn, data } = value[TOKEN_STRUCT];
        host.debug(`ANY is a struct of type ${fqn}`);
        return SERIALIZERS[SerializationClass.Struct].deserialize(
          data,
          { type: { fqn } },
          host,
        );
      }

      // At this point again, deserialize by-value.
      host.debug('ANY is a Map');
      return mapValues(
        value,
        (v, key) =>
          process(
            host,
            'deserialize',
            v,
            { type: spec.CANONICAL_ANY },
            `key ${inspect(key)}`,
          ),
        host,
      );
    },