mormot2.json.serial

复制代码
unit mormot2.json.serial;
/// <author>cxg 2023-2-11</author>
{$IFDEF fpc}
  {$MODE DELPHI}{$H+}
{$ENDIF}

interface

uses
  mormot.core.text, mormot.core.json, mormot.core.base,
  Classes, SysUtils;

type

  { TSerial }

  TSerial = class
    class function marshal<T>(const aRec: T): rawutf8;
    class function marshal2(const aObj: TObject): rawutf8;
    class function unmarshal<T>(const json: rawutf8): T;
    class procedure unmarshal2(const json: rawutf8; aObj: TObject);
  end;

implementation

{ TSerial }

class function TSerial.marshal2(const aObj: TObject): rawutf8;
begin
  Result := mormot.core.text.ObjectToJson(aObj);
end;

class function TSerial.marshal<T>(const aRec: T): rawutf8;
begin
  result := mormot.core.json.RecordSaveJson(aRec, TypeInfo(T));
end;

class procedure TSerial.unmarshal2(const json: rawutf8; aObj: TObject);
begin
  mormot.core.json.ObjectLoadJson(aObj, json);
end;

class function TSerial.unmarshal<T>(const json: rawutf8): T;
begin
  mormot.core.json.RecordLoadJson(result, json, TypeInfo(T));
end;

end.
复制代码

 

posted @   delphi中间件  阅读(168)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
历史上的今天:
2022-02-20 rtc二进制接口
2020-02-20 中间件怎样记录SQL日志
2020-02-20 怎样建立稳定的长连接的数据库连接池
2020-02-20 unidac 断线重连
2019-02-20 咏南中间件开始支持中间件桥接
2013-02-20 clientdataset<---->json
2012-02-20 TField.ProviderFlags
点击右上角即可分享
微信分享提示