Ejemplo n.º 1
0
 public static void Write(JsonWriter writer, string propertyName, TEnum item, TEnum defaultValue = default, bool required = false)
 {
     if (required || !item.Equals(defaultValue))
     {
         writer.WritePropertyName(propertyName);
         _enumConverter.WriteJson(writer, item, null);
     }
 }
Ejemplo n.º 2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!typeof(Services).Equals(value.GetType()))
            {
                throw new InvalidOperationException(string.Format("Can't use a ServicesConverter to serialize {0}", value.GetType().ToString()));
            }
            var s = (Services)value;

            switch (s)
            {
            case Services.UPS_2DA:
                writer.WriteValue("2DA");
                break;

            case Services.UPS_2DA_AM:
                writer.WriteValue("2DA_AM");
                break;

            case Services.UPS_3DA:
                writer.WriteValue("3DA");
                break;

            case Services.UPS_3DA_USA:
                writer.WriteValue("3DA_USA");
                break;

            default:
                var converter = new StringEnumConverter();
                converter.WriteJson(writer, value, serializer);
                break;
            }
        }
Ejemplo n.º 3
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!typeof(SpecialServiceCodes).Equals(value.GetType()))
            {
                throw new InvalidOperationException(string.Format("Can't use a USPSSpecialServiceCodesConverter to serialize {0}", value.GetType().ToString()));
            }
            var s = (SpecialServiceCodes)value;

            switch (s)
            {
            case SpecialServiceCodes.liveanimal_poultry:
                writer.WriteValue("liveanimal-poultry");
                break;

            case SpecialServiceCodes.sunday_holiday:
                writer.WriteValue("sunday-holiday");
                break;

            case SpecialServiceCodes.TenThirty:
                writer.WriteValue("1030");
                break;

            case SpecialServiceCodes.PO_to_Addressee:
                writer.WriteValue("PO to Addressee");
                break;

            default:
                var converter = new StringEnumConverter();
                converter.WriteJson(writer, value, serializer);
                break;
            }
        }
Ejemplo n.º 4
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (!typeof(TransactionType).Equals(value.GetType())) throw new InvalidOperationException(string.Format("Cant use TransactionTypeConverter to serialize a {0}", value.GetType().ToString())); 
     var s = (TransactionType)value;
     switch (s)
     {
         case TransactionType.POSTAGE_FUND:
             writer.WriteValue("POSTAGE FUND");
             break;
         case TransactionType.POSTAGE_PRINT:
             writer.WriteValue("POSTAGE PRINT");
             break;
         case TransactionType.POSTAGE_REFUND:
             writer.WriteValue("POSTAGE REFUND");
             break;
         case TransactionType.APV_POSTAGE_OVERPAID:
             writer.WriteValue("APV-POSTAGE OVERPAID");
             break;
         case TransactionType.APV_POSTAGE_UNDERPAID:
             writer.WriteValue("APV-POSTAGE UNDERPAID");
             break;
         default:
             var converter = new StringEnumConverter();
             converter.WriteJson(writer, value, serializer);
             break;
     }
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Enum e = (Enum)value;

            string enumName = e.ToString("G");

            if (char.IsNumber(enumName[0]) ||
                enumName[0] == '-')
            {
                // enum value has no name so write number
                writer.WriteValue(value);
            }
            else
            {
                string finalName = SnakeCasePropertyResolver.ToSnakeCase(enumName);

                _stringEnumConverter.WriteJson(writer, finalName, serializer);
            }
        }
Ejemplo n.º 6
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var action = (IndexActionBase <T>)value;

            var injectingWriter = new InjectingJsonWriter(writer);

            injectingWriter.OnStart =
                w =>
            {
                w.WritePropertyName("@search.action");

                var converter = new StringEnumConverter();
                converter.WriteJson(w, action.ActionType, serializer);
            };

            serializer.Serialize(injectingWriter, action.Document);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!typeof(TrackingStatusCode).Equals(value.GetType()))
            {
                throw new InvalidOperationException(string.Format("Cant TrackingStatusConverter use on a {0}", value.GetType().ToString()));
            }
            var s = (TrackingStatusCode)value;

            switch (s)
            {
            case TrackingStatusCode.InTransit:
                writer.WriteValue("In Transit");
                break;

            default:
                var converter = new StringEnumConverter();
                converter.WriteJson(writer, value, serializer);
                break;
            }
        }
Ejemplo n.º 8
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var action = (IndexAction <T>)value;

            void WriteActionAnnotation(JsonWriter innerWriter)
            {
                innerWriter.WritePropertyName("@search.action");

                var converter = new StringEnumConverter();

                converter.WriteJson(innerWriter, action.ActionType, serializer);
            }

            var injectingWriter = new InjectingJsonWriter(writer)
            {
                OnStart = WriteActionAnnotation
            };

            serializer.Serialize(injectingWriter, action.Document);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!typeof(PackageLocation).Equals(value.GetType()))
            {
                throw new InvalidOperationException(string.Format("Can't use PackageLocationConverter on a {0}", value.GetType().ToString()));
            }
            var s = (PackageLocation)value;

            switch (s)
            {
            case PackageLocation.FrontDoor:
                writer.WriteValue("Front Door");
                break;

            case PackageLocation.BackDoor:
                writer.WriteValue("Back Door");
                break;

            case PackageLocation.SideDoor:
                writer.WriteValue("Side Door");
                break;

            case PackageLocation.KnockonDoorRingBell:
                writer.WriteValue("Knock on Door / Ring Bell");
                break;

            case PackageLocation.MailRoom:
                writer.WriteValue("Mail Room");
                break;

            case PackageLocation.InAtMailbox:
                writer.WriteValue("In / At Mailbox");
                break;

            default:
                var converter = new StringEnumConverter();
                converter.WriteJson(writer, value, serializer);
                break;
            }
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!typeof(ParcelType).Equals(value.GetType()))
            {
                throw new InvalidOperationException(string.Format("Can't use a ParcelTypeConverter to serialize {0}", value.GetType().ToString()));
            }
            var s = (ParcelType)value;

            switch (s)
            {
            case ParcelType.UPS_10KG:
                writer.WriteValue("10KG");
                break;

            case ParcelType.UPS_25KG:
                writer.WriteValue("25KG");
                break;

            default:
                var converter = new StringEnumConverter();
                converter.WriteJson(writer, value, serializer);
                break;
            }
        }
 public override void WriteJson(JsonWriter writer, ChangeReason value, JsonSerializer serializer)
 {
     _converter.WriteJson(writer, value, serializer);
 }
Ejemplo n.º 12
0
 public override void WriteJson(JsonWriter writer, T?value, JsonSerializer serializer)
 {
     converter.WriteJson(writer, value, serializer);
 }