19
votes

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?

1

1 Answers

31
votes

you can override your Guid serializer as

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