

const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
const require_ClassValidationError = require('../error/ClassValidationError.js');
const require_MessageValidator = require('./MessageValidator.js');
let class_transformer = require("class-transformer");
class_transformer = require_rolldown_runtime.__toESM(class_transformer);

//#region src/utils/JsonTransformer.ts
var JsonTransformer = class JsonTransformer {
	static toJSON(classInstance) {
		return (0, class_transformer.instanceToPlain)(classInstance, { exposeDefaultValues: true });
	}
	static fromJSON(json, cls, { validate = true } = {}) {
		const instance = (0, class_transformer.plainToInstance)(cls, json, { exposeDefaultValues: true });
		if (!validate) return instance;
		if (!instance) throw new require_ClassValidationError.ClassValidationError("Cannot validate instance of ", { classType: Object.getPrototypeOf(cls).name });
		require_MessageValidator.MessageValidator.validateSync(instance);
		return instance;
	}
	static clone(classInstance) {
		return (0, class_transformer.instanceToInstance)(classInstance, {
			exposeDefaultValues: true,
			enableCircularCheck: true,
			enableImplicitConversion: true,
			ignoreDecorators: true
		});
	}
	static serialize(classInstance) {
		return JSON.stringify(JsonTransformer.toJSON(classInstance));
	}
	static deserialize(jsonString, cls, { validate = true } = {}) {
		return JsonTransformer.fromJSON(JSON.parse(jsonString), cls, { validate });
	}
};

//#endregion
exports.JsonTransformer = JsonTransformer;