In v8.5 how do I prevent JsonApiClient from removing hyphens from a GUID?

I have a simple console application that calls an API. The DTO has a GUID in it:

public class Hello
{
public Guid Id { get; set; }
}

public class HelloResponse
{
public string Result { get; set; }
}

The Program.cs sets the Id to a GUID.

class Program
{
static void Main(string args)
{
var baseUri = “http://10.0.0.130:20600”;
var client = new JsonApiClient(baseUri);

        var request = new Hello
        {
            Id = new Guid("36b52f59-d45c-4991-9680-b0d41536690b")
        };
        var response = client.Get<HelloResponse>(request);

        Console.WriteLine(response.Result);
    }
}

If I sniff the network I find that the call GUID gets changed. The hyphens are removed

image

How do I prevent the hyphens from being removed as it causes issues with serialization?

It wont cause serialization issues since the QueryString on the server is still deserialized using ServiceStack.Text which is resilient into accepting multiple formats.

The QueryString is serialized using ServiceStack.Text so you should be able to configure it on the client with JsConfig:

JsConfig<Guid>.SerializeFn = guid => guid.ToString("D");

Otherwise you could change the property to use a string if you want to precise control over what’s sent.

@mythz Thanks for the prompt reply.
I have setting up the server to format the Guid as suggested

public class AppHost() : AppHostBase(“WebAPI”), IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
JsConfig.SerializeFn = guid => guid.ToString(“D”);
builder.ConfigureServices((context, services) =>
{
// Configure ASP.NET Core IOC Dependencies
context.Configuration.GetSection(nameof(AppConfig)).Bind(AppConfig.Instance);
services.AddSingleton(AppConfig.Instance);
});
}

// Configure your AppHost with the necessary configuration and dependencies your App needs
public override void Configure()
{
    SetConfig(new HostConfig());
}

}

but it is still get the following error

{
“responseStatus”: {
“errorCode”: “SerializationException”,
“message”: “Could not deserialize ‘application/json’ request using SENPOS.Request.TableTracking.TableChargeRequest’\nError: The JSON value could not be converted to System.Guid. Path: $.TableSaveInfo.SaleItems[0].GUID | LineNumber: 1 | BytePositionInLine: 41.”,
“errors”:
}
}

If you want to control it on the client it needs to be configured on the client, i.e. where JsonApiClient is used.

BTW are you explicitly configuring JsonApiClient to use /json/reply? As it defaults to /api why is it showing /json/reply/Hello? Also if the Hello API doesn’t have an explicit IGet marker it should be sending a POST instead which is the default Primary HTTP Method. So I don’t think this is the right capture for this request.

Can you include the full Request/Response for the same request so I can see exactly which request is causing which error server response.

Apologies if I caused some confusion. The initial code I sent for “Hello” was a test application. The real application is more complex. The request is as below

POST /TableTracking/TableCharge/2013 HTTP/1.1
Host: 10.0.0.130:20600
Content-Type: application/json
User-Agent: insomnia/10.2.0
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImctTDk3c2FQOE5HcGJMYVlmQ1JOSG5USThacyIsImtpZCI6ImctTDk3c2FQOE5HcGJMYVlmQ1JOSG5USThacyJ9.eyJpc3MiOiJodHRwczovL3Nzby5teXR4dC5jb20uYXUiLCJhdWQiOiJodHRwczovL3Nzby5teXR4dC5jb20uYXUvcmVzb3VyY2VzIiwiZXhwIjoxNzMzOTU0MTk3LCJuYmYiOjE3MzM5NTI5OTcsImNsaWVudF9pZCI6InNlZyIsInNjb3BlIjpbIm9wZW5pZCIsInJlc291cmNlX2FjY2VzcyJdLCJzdWIiOiJzZW5wb3MiLCJhdXRoX3RpbWUiOjE3MzM5NTI5OTcsImlkcCI6Imlkc3J2IiwicmVzb3VyY2VfYWNjZXNzIjoiQWxsIiwianRpIjoiNzZkM2VmNDRmZGMxZmY0OGQ5MjNiNWRhNjI2MTNkZmYiLCJhbXIiOlsicGFzc3dvcmQiXX0.lE2BrDIx4nOC3qq_95ehcYOkVuT5x_eeUPKxtA0llQSSeT8N-ldk6mr9pHXSlFAd3dEGfvuxKj6hLUwFWaFsYlA-UhYHmj-metRUEDv7WvmiZnk5H22ul2WVmorly_6qTLfqo6mFweMC3wTJEspcuf4LxWX2tGN9ePPwYtT864XyZZjwEFMKAJ0TUOBAVnSSOZLr4qKzmjHH6EeCHuBqRL5cFbyrnx_TcGUepJ3bjwzPFg-WwtBSwRGxmTIn2BYYEOdAMWUhxO8mY3Nr8swqFtvCdXd6MrwbaPGvLF71gBfxiT8yKIEvtlStCAIjXjIWxaBVmQgu1_CQr0TMHDQcOA
Accept: /
Content-Length: 1280

| {“TblID”:2013,“TableSaveInfo”:{“SaleItems”:[{“ItemID”:903,“Quantity”:1,“PriceLevelType”:0,“Price”:26.5,“OriginalPrice”:0,“PLUPriceLevelID”:1,“DefaultPrice”:26.5,“Description”:“Coq Au Vin”,“DepartmentID”:55,“PromotionDiscount”:0,“ItemType”:“PLU”,“ItemSubType”:0,“TimeCreated”:“2025-01-30T11:43:15.9317740+11:00”,“TimeModified”:“2025-01-30T11:43:15.9332038+11:00”,“SubItems”:,“SeatNumber”:1,“PrintedQuantity”:0,“Group”:" Mains",“Taxable”:true,“PrintStyleID”:17,“isRemovable”:true,“PrintOrder”:40,“ShortDescription”:“Coq Au Vin”,“SubGroup”:“Nineteen 21 Mains”,“IsSelected”:false,
| “GUID”:“cf97e4dee5b440ddab28514ca6764826”,“RelatedItems”:,“NotificationOutletID”:0,“PromotionTrackingIDs”:,“PriceCalcs”:[{“PromotionDetailID”:0,“Priority”:0,“Calculation”:“[GUESTS]”,“Description”:“Initial price”,“PLUPriceLevelID”:1,“PLUPriceLevelType”:“Normal”,“CalculatedPrice”:26.5,“Discount”:0.0,“Valid”:true,“HasCalcError”:false}],“PointsCalcs”:,“PromotionScores”:,“ApprovedMemberPoints”:,“Amount”:26.5,“DiscountAmount”:0.0,“AmountTotal”:26.5,“TotalAmount”:26.5,“GST”:2.41,“FullDescription”:“Coq Au Vin”}],“ReceiptNumber”:31475,“Terminal”:{“ID”:7,“Code”:0},“SaleDateTime”:“0001-01-01T00:00:00.0000000”,“CashDrawer”:0,
| “GUID”:“78af332aed90496e92e95100570f606f”,“SaleHoldType”:“SaleHold”}}

The response is

{
“responseStatus”: {
“errorCode”: “SerializationException”,
“message”: “Could not deserialize ‘application/json’ request using SENPOS.Request.TableTracking.TableChargeRequest’\nError: The JSON value could not be converted to System.Guid. Path: $.TableSaveInfo.SaleItems[0].GUID | LineNumber: 1 | BytePositionInLine: 41.”,
“errors”:
}
}

Right, it’s being send as a HTTP POST with a JSON Request Body. This has nothing to do with the QueryString?

If I put the hyphens back into the GUIDs then it is successful

Put it back where, in the Request DTO when using the JsonApiClient? Or did you just change the JSON request body in fiddler?

Are you using JsonApiClient for this request? Have you configured the JsConfig on the client?

I changed the JSON in fiddler.
I have not configured the JsConfig on the client. How would I do that?

Exactly the same way:

JsConfig<Guid>.SerializeFn = guid => guid.ToString("D");

In .NET 8 clients you can also force JsonApiClient to use System.Text.Json for de/serializing JSON requests/responses with:

ClientConfig.UseSystemJson = UseSystemJson.Always;

Thanks. I will try that and get back to you.

@mythz Thanks for the solution.
I put

JsConfig.SerializeFn = guid => guid.ToString(“D”);

into the client and it has resolved my issue.