2
votes

i'm using servicestack and retrieving data from DB with ORMLite. Some of the DB's rows are strings and some of them needs to be whitespaces-trimmed before they are sended to the client like:

    {... ,"folderCode":"5150001     ",....}

Does ORMLite offer a way to trim strings during object mapping? Or does ServiceStack offer a way to trim strings during serialization?

Thanks in advance!

1

1 Answers

2
votes

If you only need this done on a few specific properties of a class, you can use the OnSerializingFn.

Given a DummyClass with a FolderCode property that you want serialized

public class DummyClass
{
    public string FolderCode { get; set; }
}

Then override the OnSerializingFn

JsConfig<DummyClass>.OnSerializingFn = obj =>
{
    obj.FolderCode = obj.FolderCode.Trim();
    return obj;
};