JSON: Serialize GUIDs without braces from a VCL Server for a REST endpoint?

Hello,

I am exposing several methods from my app server for a HTTP API REST endpoint to be consumed by REST clients.

In my unit tests, using xUnit from .NET, I added some new tests that validate the values returned by the server, and part of the test is serializing the response into the corresponding type. The types are generated by rodl2code for .net/c# from the same RODL used in the server. Those same types are used in the “normal” tests that try the methods using RO-SDK transports.

I am seeing that the JSON deserializer used by the .NET unit tests can’t understand the GUIDs we return from the server because they are in the B format: using braces, which, IIRC, is the one used by default in the Delphi RTL.

I can change the deserializer in the tests to use some other, Newtonsoft for instance I believe can work with that kind of format, but as I am not in control of what the clients will be based on, I would prefer if we can use the “D” format, which I understand is the official format, for the GUIDs for the Server directly. Is there any way to configure this on the server?

Thanks!

Hi,

weird.
We use this code for reading guids in JsonSerializer:

        public override Guid ReadGuid(String name)
        {
            var value = IntReadString(name);
            return (String.IsNullOrEmpty(value)) ? Guid.Empty : new Guid(value);
        }

according to this simple test, delphi-style guids are fully supported:

Hello Evgeny,

Ok… I was referring to the .NET serializer: System.Text.Json, which I don’t know why it doesn’t like the curly GUIDs, as .NET itself do understand them as your code shows. I haven’t tried RO serializer, which I understand is what you are referring to?

I changed that for the Newtonsoft.Json serializer and it understand curly-GUIDs without issues. My problem was not changing my .NET code to consume that format, but trying to avoid problems for future users of this API services: have the option to serialize the GUIDs in a different format from the server.

Thanks!

Hi,

we have no standard how to serialize guid at https://www.json.org/json-en.html.
guid is just a string. we used Delphi style because .NET understands it.