Google's Protocol Buffers are a flexible, compact and extensible mechanism for serializing structured data. We share our implementation that makes it easy to serialize Delphi records to a binary format that is 100% compatible with the Protocol Buffers specification. Want to go straight to the source?
JSON format spread over the years and became preferred lightweight protocol for data exchange. Delphi natively supports JSON via the classes in the System.JSON unit. But dealing with TJsonObject requires an intermediate layer for mapping JSON values to our business logic. Recent Delphi releases make it easier to load JSON data to a specific BL class with the help of TJson.JsonToObject. But in all cases the developer should manually create these BL classes which can be time consuming operation. The missing part is the JSON Data binding wizard.
Json to class generators are not something new. There is already / but these cover C#. I couldn’t find such class generator for Delphi. So the JsonToDelphiClass was born. It analyses given JSON string, visualizes it in an easy to read way (in a treeview) and generates corresponding delphi classes (business objects). Just what XML Data binding wizard does for XML. Main features: • Build entirely on the RTL (no external dependencies) so it’s cross-platform; • Accepts any valid JSON string, no matter how complex the object is; You can validate JSON strings. • Visualizes the structure of the JSON objects in a treeview; • Generates complete delphi unit (declaration and implementation), based on the JSON string input; • Automatically prefixes reserved Delphi words with “&” (ampersand); • Automatically prevents class name collisions by using numeric suffixes; • * Blocks unit generation if the JSON string contains empty Array; • Adds support code to automatically destroy complex sub types.
So you don’t have to manage subobject’s lifetime manually; • ** Uses TArray to represent lists; • Adds helper serialization/deserialization functions; • Serialization and deserialization results in the same JSON structure! • Automatically detects date/datetime parts and maps them to TDate/TDateTime (as long as dates are ISO8601 compliant); • Maps all numbers to Double; • Maps true/false values to Boolean; • Allows you to change property names (keys); • Allows you to change the names of the stub classes; • All fields in stub classes are sorted alphabetically; • Supports JSON pretty print to format the input string; • Simple and responsive GUI; • *** Automatic check for update, based on ITask (Parallel Programming Library)! • It’s open source! You can find the source code and binary releases on GitHub; • The program uses MadExcept to report unhanded exceptions; * If the JSON array is empty the contained type is unknown. Unit generation works only with known and supported types. ** This is because serialization of TList adds “noise” i.e. Includes internal properties that did not exist in the original JSON string.
*** The releases of JsonToDelphiClass (source and binaries) are public and reside on GitHub. Durufle Prelude Fugue Alain Pdf To Jpg. The update unit uses GitHub’s REST API to enumerate tags/releases.
I decided to use Firemonkey (XE7). It was a big challenge, because I faced many problems! So this slowed me down because I had to submit QCs i find workarrounds:,,,,,. Hopefully these QCs will be fixed soon. Still there are a few nasty bugs, but it’s hard to reproduce them for QC reports: • At first show the main Popup menu is badly clipped: • The Treeview changes items’ height when you press Visualize button two or more times; • One possible issue with MadExcept and Report Resource Leaks feature; If I have free time I’ll dig into these bugs.
But the final result looks good and should compile for MAC OS! BTW uGitHub.pas is generated by the JsonToDelphiClass itself 🙂 The idea of automatic update check is not something new to me. I’ve done this hundreds of times before. But this is the. I am pleasantly surprised from what GitHub offers – and! Which made me play with Delphi REST components. This program uses *very simple* check for update mechanism.
The user is only notified for new version availability, but do not automatically download the new version! Git REST API require the use of SSL. This is why I needed to use OpenSSL binaries.
And by the way I finally got it to know why the first call to idHTTP.GET is soooo slow (about 3 sec.) with SSL: LoadOpenSSLLibrary calls InitializeRandom. The next call to _RAND_Screen()! This is why the program cannot terminate immediately. Update checker uses the new Parallel Programming library and especially ITask.
The program demonstrates basic ITask usage, GUI responsiveness and clean termination. The UI is simple and User experience is good enough: • The UI don’t freeze; • The treeview supports a PopUp menu that allows you to rename properties and classes. The F2 key also works; • The JSON string memo supports JSON prettify feature, available through mouse double click or from the context menu; • The Save Dialog automatically receives the name of the target Delphi unit; • The Main Form is re-sizable and have minimum constraints set; • You can horizontally resize the main panels using the splitter; • You are notified if there is newer version. An additional form shows more details: Simple usage: • Paste a into the memo. You can prettify it with double click inside the memo; • Press the “Visualize” button.
On the left you will see the future class structure – properties and types; • Edit the structure if you need to. You can rename properties and classes with right-click or F2; • Press “Preview Unit” button to see the generated unit; • Save the generated unit; IMPORTANT: The generated unit is compatible with Delphi XE5 or later. Backward compatibility is planned. MEANWHILE if you need to compile the generated units with older versions, please remove/comment out the ToJsonString/FromJsonString and remove Rest.Json and System.Json units from the USES clause.
EXTERNAL REVIEW: I was pleasantly surprised to find a review of JsonToDelphiClass here:. Thanks to FMX Express team! PROJECT INFORMATION: GitHub Project link: GitHub Releases link: The archive JsonToDelphiClass-A.BC.zip contains the release version of the program along with libeay32.dll and ssleay32.dll. I plan to play with UPX to further reduce exe size. Feel free to report any problems/suggestions using. This entry was posted in, and tagged,,,,,,,,,,,,,. Bookmark the.
Hello, Stephane! RTL’s JSON marshaler will add some “noise” when converting a TList object to JSON string i.e. It will include some internal properties.
This would make the JSON string incompatible/unreadable by other consumers. That’s why I chose to use TArray since it serializes as expected and according to the JSON specifications. I know it is inconvenient. May be I can plan to add an option to choose the type of arrays (TArray/TList) in future versions. It seems I didn’t synced the last source code to GitHub.
I’ll do it soon. How to use that class?
(I know, nobody expect that question, but when I got to work with complicated JSON, I can’t go forward. I create unit using Your program (it’s great), but it generated 3 classes, and I can’t put it together to one JSON result I have got procedure: procedure TForm6.Button3Click(Sender: TObject); var test:unit7.TRootClass; test2:unit7.TErrors_dataClass; test3:unit7.TItemClass; begin test2:=unit7.TErrors_dataClass.Create; test2.artykul:=’art1′; test2.code:=’code’; test3:=unit7.TItemClass.Create; test3.errors:=’err1′; test3.link_plik:=’link1′; test3.errors_data[0].FromJsonString(test2.ToJsonString).
Hi, I have very low to no knowledge of JSON. Rush Hour 1 In Hindi Mp4 Free Download more. So, I maybe asking my question wrongly here. Hope it will be understandable. There is this C# application with code available to me which uses a C# DLL. I am writing a Delphi application which uses that same C# DLL. I see that at some point C# application using JsonConvert.SerializeObject() and JsonConvert.DeserializeObject() functions when I check the code.
I do not know how to do that, so I appreciate someone helps me out. Record structure to Serialize. Hi, I have very low to no knowledge of JSON. So, I maybe asking my question wrongly here.
Hope it will be understandable. There is this C# application with code available to me which uses a C# DLL. I am writing a Delphi application which uses that same C# DLL. I see that at some point C# application using JsonConvert.SerializeObject() and JsonConvert.DeserializeObject() functions when I check the code. I do not know how to do that, so I appreciate someone helps me out. Record structure to Serialize. Click to expand.The variable 'szJsonPairing_Out' is an ordinary byte array, that is returned from the device and the method 'GMP_Tools.SetEncoding(szJsonPairing_Out)' transforms the bytes back into the string which is surley a JSON.
Probably the byte array is encrypted, because an extra functione exists. Maybe it's only an ASCII code. I cannot believe that there is a special encoding implemented, but without to see the data hard to say. The question is again, what do you plan to do. Do you want to replace the C# DLL? Or do you want to use it? Propably the C# DLL itself is using a C or C++ DLL, that it would be much easier to implement code with Delphi, because it should be easy to use the C/C++ DLL.
The variable 'szJsonPairing_Out' is an ordinary byte array, that is returned from the device and the method 'GMP_Tools.SetEncoding(szJsonPairing_Out)' transforms the bytes back into the string which is surley a JSON. Probably the byte array is encrypted, because an extra functione exists. Maybe it's only an ASCII code. I cannot believe that there is a special encoding implemented, but without to see the data hard to say.
The question is again, what do you plan to do. Do you want to replace the C# DLL?
Or do you want to use it? Propably the C# DLL itself is using a C or C++ DLL, that it would be much easier to implement code with Delphi, because it should be easy to use the C/C++ DLL. Click to expand.I wrote in my first post that I will be using C# DLL within Delphi. Actually, I have to use it since there is nothing more I am provided other than a sample C# code that shows how to use C# DLL. I am positive that C# DLL is only DLL sample application uses. Company tells that is all they have. As I could get serialized json data that passed to DLL function, I understand that string values are first converted into Byte arrays and then Base64 encoded.
That is easy to handle, and I already wrote my functions for them. However, numbers are different story. As far as I understand they are first converted to BCD (and then most likely Base64 encoded like strings). Though BCD conversion is not regular C# functions.
There are 3-4 separate functions written specific to ARM processor as far as I understand from very limited and Non-English remarks. I am now trying to figure that BCD conversion routines. I believe, I will be able to work on json formatting after solving BCD conversions in Delphi.
Btw, I do appreciate all help. Json is not a big deal anymore after reading links provided about it. As my problem here turned into something other than json, now. Code: procedure GetErrorMessage(ErrorCode: UInt32; Buffer: array of Byte); cdecl; external 'GMPSmartDLL.dll'; function Json_FiscalPrinter_Echo(szEcho_Out: array of Byte; EchoLen_Out, TimeoutInMiliseconds:integer): UInt32; cdecl; external 'GMPSmartDLL.dll'; function Json_GMP_StartPairingInit(szPairing: string; szPairingResp: array of Byte; PairingRespLen: Integer): Uint32; cdecl; external 'GMPSmartDLL.dll'; I thought it as a C# DLL. Since you referred in your post 'normal' what is 'normal' DLL, anyway?