首页 > 其他分享 >mormot2.json.serial

mormot2.json.serial

时间:2023-02-20 12:34:00浏览次数:43  
标签:core const TSerial rawutf8 json mormot2 serial class

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.

 

标签:core,const,TSerial,rawutf8,json,mormot2,serial,class
From: https://www.cnblogs.com/hnxxcxg/p/17136907.html

相关文章

  • JS字符串和json转换
    <head><scriptsrc="jquery-1.8.0.min.js"type="text/javascript"></script><scriptsrc="jquery.json-2.4.js"type="text/javascript"></script></head>varst......
  • mormot2 http路由
    mormot2http路由mormot.net.server.pas重写包括2部分:重写URL+重写HTTPMETHOD。如果你用过GO就会惊喜地发现它与GO的HTTP路由非常相似以及更加方便。///efficient......
  • Fastjson2基础使用以及底层序列化/反序列化实现探究
    1Fastjson2简介Fastjson2是Fastjson的升级版,特征:协议支持:支持JSON/JSONB两种协议部分解析:可以使用JSONPath进行部分解析获取需要的值语言支持:Java/Kotlin场景支持:An......
  • Django Rest Frame work 如何使用serializers序列化函数新手教程
    DjangoRestFramework如何使用serializers序列化   DjangoRestFramework提供了serializers模块,用于序列化和反序列化模型实例以及原生数据类型......
  • Django Rest Frame work 如何使用serializers序列化
    DjangoRestFramework如何使用serializers序列化   DjangoRestFramework提供了serializers模块,用于序列化和反序列化模型实例以及Python原生数......
  • serializers序列化函数简单入门
    1.创建Django项目和应用程序首先,我们需要创建一个Django项目和一个Django应用程序。如果你已经有了Django项目和应用程序,请跳过这一步。$django-adminstartprojectm......
  • (转)vue 利用js触发vue-json-excel的下载操作,解决多次下载等问题
    转载地址:https://www.jianshu.com/p/4d716bec3a26 需求:列表中的每行数据都有一个导出按钮,且点击导出会发起网络请求,获取激活码列表数据。分析:我使用的vue-json-excel......
  • 【Cesium】拿取后台geojson数据绘制图形
    cesiumDraw标绘类mars3d.Draw是实体类,标绘控制处理类,提供文字、点、线、面、立体、模型等各类entity对象的绘制。需求:拿取请求的json数据绘制区域书写基础绘制方法......
  • JSON_UNESCAPED_SLASHES json 不转义反斜杠
    JSON_UNESCAPED_SLASHESJSON_UNESCAPED_UNICODE的意思不要转移汉字,我们在学习使用的时候经常使用这个选项。而JSON_UNESCAPED_SLASHES是用于不要转义反斜杠,在这里选择这......
  • mormot2中间件
    mormot2中间件中间件同一份pascal源码,同时支持在DELPHI和LAZARUS下面开发编译。 DELPHI编译目标平台WIN32,WIN64,LINUXINTEL64位CPU,主要是WINDOWS平台,因为DELPHI在W......