From 75d3b7331c0455cefc5a073f80fef91a1d15df3e Mon Sep 17 00:00:00 2001 From: maiconsaraiva Date: Thu, 28 Dec 2023 15:41:56 -0300 Subject: [PATCH] #219 - Implementado tratamento para FieldType = ftBytes --- src/DataSet.Serialize.Export.pas | 11 ++++++++++- src/DataSet.Serialize.Import.pas | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/DataSet.Serialize.Export.pas b/src/DataSet.Serialize.Export.pas index ce92e12..cac3e14 100644 --- a/src/DataSet.Serialize.Export.pas +++ b/src/DataSet.Serialize.Export.pas @@ -163,6 +163,8 @@ function TDataSetSerialize.ToJSONObject: TJSONObject; function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const IsChild: Boolean; const IsValue: Boolean = True; const IsEncodeBlob: Boolean = True): TJSONArray; var LBookMark: TBookmark; + LHexString: String; + LByteValue: Byte; begin Result := TJSONArray.Create; if ADataSet.IsEmpty then @@ -238,6 +240,13 @@ function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const Is else Result.Add(ADataSet.Fields[0].AsString); end; + TFieldType.ftVarBytes, TFieldType.ftBytes: + begin + LHexString := EmptyStr; + for LByteValue in ADataSet.Fields[0].AsBytes do + LHexString := LHexString + IntToHex(LByteValue, 2); + Result.Add(LHexString); + end else raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [ADataSet.Fields[0].FieldName]); end; @@ -370,7 +379,7 @@ function TDataSetSerialize.DataSetToJSONObject(const ADataSet: TDataSet; const A {$ENDIF} TFieldType.ftGraphic, TFieldType.ftBlob, TFieldType.ftOraBlob, TFieldType.ftOraClob{$IF NOT DEFINED(FPC)}, TFieldType.ftStream{$ENDIF}: Result.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(LKey, TJSONString.Create(IfThen(FEncodeBase64Blob, EncodingBlobField(LField), LField.AsString))); - TFieldType.ftVarBytes: + TFieldType.ftVarBytes, TFieldType.ftBytes: begin LHexString := EmptyStr; for LByteValue in LField.AsBytes do diff --git a/src/DataSet.Serialize.Import.pas b/src/DataSet.Serialize.Import.pas index 1e396d7..da3ade8 100644 --- a/src/DataSet.Serialize.Import.pas +++ b/src/DataSet.Serialize.Import.pas @@ -458,7 +458,7 @@ procedure TJSONSerialize.JSONObjectToDataSet(const AJSONObject: TJSONObject; con LField.AsString := LJSONValue.Value; end; end; - TFieldType.ftVarBytes: + TFieldType.ftVarBytes, TFieldType.ftBytes: begin SetLength(LBytes, Length(LJSONValue.Value) div 2); LHex := 1;