ServiceStack.Java Serialization of System.DayOfWeek

Hello,

I’m trying to return a response object that contains a System.DayOfWeek type however the generated Java code does not generate the enumeration. I’m guessing that you don’t create enums that are inside the System namespace.

I tried importing the java.time.* namespace in the generated code to have the response object use Java’s built-in type but the deserialized value is NULL (looks like the deserialization case sensitive).

Here’s my response object:

    public class HelloResponse : BaseResponse
    {
        public string Result { get; set; }
        public DayOfWeek Day { get; set; }
    }

I’m currently treating this type as a string in my code but it would be nice to have an enum. Is it possible to create a custom serializer/deserializer to handle this type?

Thanks

You can now use the new ExportTypes collection to export System types and enums so they’re included in the generated DTO’s. To add the type you need to add it on the pre-registered NativeTypesFeature in your AppHost, e.g:

var nativeTypes = this.GetPlugin<NativeTypesFeature>();
nativeTypes.MetadataTypesConfig.ExportTypes.Add(typeof(DayOfWeek));

Which lets you have the DayOfWeek enum in your DTO’s, e.g:

public class HelloBuiltin
{
    public DayOfWeek DayOfWeek { get; set; }
}

Which now gets emitted like any other enum, e.g. in Java:

public static enum DayOfWeek
{
    Sunday,
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday;
}

This change is now supported from the latest v4.0.45 of ServiceStack that’s now available on MyGet.