How to use the class-transformer.deserialize function in class-transformer

To help you get started, we’ve selected a few class-transformer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tokilabs / plow / src / eventSourcing / eventStoreProviders / gesEventStore.ts View on Github external
private convertToEnvelope(event: EventStore.ResolvedEvent): EventEnvelope {
    const e = event.event;

    const metadata = JSON.parse(e.metadata.toString());
    const eventClass = requireByFQN(e.eventType);

    return new EventEnvelope(
      new Guid(e.eventId),
      metadata.aggregateType, // aggregateType
      metadata.aggregateId, // aggregateId
      e.eventNumber, // version
      deserialize(eventClass, e.data.toString()), // eventData
      e.eventType, // eventType
      metadata,
      new Date(e.createdEpoch) // created
    );
  }
github enqueuer-land / enqueuer / src / service / requisition / requisition-parser.js View on Github external
RequisitionParser.prototype.deserialize = function (requisitionJson) {
        try {
            return class_transformer_1.deserialize(requisition_1.Requisition, requisitionJson);
        }
        catch (e) {
            throw new Error("Error parsing requisition: " + e);
        }
    };
    return RequisitionParser;
github node-ts / bus / packages / bus-core / src / serialization / json-serializer.ts View on Github external
deserialize (val: string, classConstructor: ClassConstructor): T {
    return deserialize (classConstructor, val)
  }
github 52North / helgoland / www / src / services / api-interface / api-interface.service.ts View on Github external
return this.requestApiTexted(url, params).map((result) => {
            const timeseries = deserialize(Timeseries, result);
            timeseries.url = apiUrl;
            return timeseries;
        });
    }
github danielwii / asuna-node-server / src / modules / common / helpers / validate.ts View on Github external
options: ClassTransformOptions = { enableCircularCheck: true },
): T {
  if (!json) {
    return;
  }

  if (json instanceof cls) {
    validateObjectSync(json);
    return json as T;
  }

  let o;
  if (_.isPlainObject(json)) {
    o = plainToClass(cls, json as JSON, options);
  } else if (_.isString(json)) {
    o = deserialize(cls, json as string, options);
  }

  logger.debug(`deserializeSafely: ${r({ cls, o, json, options })}`);
  validateObjectSync(o);
  return o;
}
github enqueuer-land / enqueuer / src / mqtt / mqtt-requisition-parser.ts View on Github external
parse(mqttRequisition: string): any {
        try {
            return deserialize(MqttRequisition, mqttRequisition);
        } catch (e) {
            throw new Error("Error parsing mqttRequisition: " + e);
        }
    }
github mabuonomo / yggdrasil-ts / src / graphql-resolver / signResolver.ts View on Github external
async signUp(@Arg("newUser") newUser: UserInput): Promise {

        var json = JSON.stringify(newUser);
        var user = deserialize(UserModel, json);
        user.password = hashSync(newUser.password, 10);

        var user = await this.userController.save(user);
        return user;
    }
}
github nicolaspearson / node.api.boilerplate / src / subscribers / SocketEventSubscriber.ts View on Github external
public onSocketServerAction(action: { type: string; data: any }) {
		if (!action || !action.type || !action.data) {
			this.appLogger.winston.error(
				`Error: Unable to process action`,
				action
			);
		}
		try {
			const eventData: EventData = deserialize(
				EventData,
				JSON.stringify(action.data),
				{
					enableCircularCheck: true
				}
			);
			const eventAction: EventAction = new EventAction();
			eventAction.data = eventData;
			eventAction.type = action.type;
			const clientId = action.data.socket.id;
			this.appLogger.winston.log(
				'socket',
				`Action Received: ${JSON.stringify(eventAction)}`
			);
			this.appLogger.winston.log(
				'socket',
github 52North / helgoland / src / app / toolbox / services / api-interface / api-interface.service.ts View on Github external
return this.requestApiTexted(url, params).map((result) => {
            const timeseries = deserialize(Timeseries, result);
            timeseries.url = apiUrl;
            return timeseries;
        });
    }