How to get ServiceStack to format Guids with dashes when using JSON?

Using ServiceStack to return a simple User object from a Post.

The user object is pretty simple:

public class User
{
    public Guid Id { get; set; }
    public string Username { get; set; }
}

The post method:

public override object OnPost(User user)
{
    User newUser;
    // Do stuff to user...
    return newUser;
}

My issue is that ServiceStack formats the Guid without dashes, so the JSON response looks e.g. like this:

{"id":"c884ce020ec94c65a8788c2ddc500434","username":"new user name"}

The client is an Android/Java client and the UUID.fromString() method does get upset about this format.

Is there any way to force ServiceStack to return a Guid formatted with dashes?

Answers


you can override your Guid serializer as

ServiceStack.Text.JsConfig<Guid>.SerializeFn = guid => guid.ToString();

Need Your Help

Xcode 7.3 debugger not showing custom class variables

ios objective-c xcode cocoapods xcode7.3

I recently updated to Xcode 7.3 , however while debugging at break points , the objects show in the debug area but clicking the triangle to reveal the variables does nothing .

How to upload bundled and minified files to Windows Azure CDN

azure asp.net-mvc-4 cdn bundling-and-minification asp.net-optimization

I'm using the ASP.NET MVC 4 bundling and minifying features in the Microsoft.AspNet.Web.Optimization namespace (e.g. @Styles.Render("~/content/static/css")).