/// <summary>
        ///     Configures the ServiceStack.Text json serializer.
        /// </summary>
        /// <param name="serializer">The individual serializer to configure.</param>
        /// <exception cref="MemberAccessException">
        /// Unable to find the deserializer property or field member on the ServiceStack.Text serializer.
        /// </exception>
        public static void ConfigureSerializer <T>(this IServiceStackSerializer <T> serializer)
        {
            if (serializer == null)
            {
                //nothing to do
                return;
            }

            //JsConfig is not thread safe.
            lock (Mutex)
            {
                if (serializer.UseRawSerializer)
                {
                    JsConfig <T> .RawSerializeFn = serializer.Serialize;
                    JsConfigWrapper <T> .SetRawDeserializerMember(serializer.Deserialize);
                }
                else
                {
                    JsConfig <T> .SerializeFn = serializer.Serialize;
                    JsConfigWrapper <T> .SetDeserializerMember(serializer.Deserialize);
                }

                var type = typeof(T);

                if (type.GetTypeInfo().IsValueType)
                {
                    //register nullable
                    var genericMethod = NullableSerializerMethodInfo.MakeGenericMethod(type);
                    genericMethod.Invoke(serializer, new object[] { serializer });
                }
            }
        }
 private static void ConfigureNullableSerializer <T>(this IServiceStackSerializer <T> serializer) where T : struct
 {
     //ServiceStack.Text will never use the serialize / deserialize fn if the value is null
     //or the text is null or empty.
     if (serializer.UseRawSerializer)
     {
         JsConfig <T?> .RawSerializeFn = arg => serializer.Serialize(arg.Value);
         JsConfigWrapper <T?> .SetRawDeserializerMember(s => serializer.Deserialize(s));
     }
     else
     {
         JsConfig <T?> .SerializeFn = arg => serializer.Serialize(arg.Value);
         JsConfigWrapper <T?> .SetDeserializerMember(s => serializer.Deserialize(s));
     }
 }