Ejemplo n.º 1
0
        /// <summary>
        /// Converts an Object to a JSON value. Any fields marked with the [SensitiveData] attribute tag will be nulled out.
        /// </summary>
        /// <typeparam name="T">The type of </typeparam>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string ObjToJson <T>(this T input)
        {
            if (input == null)
            {
                return(null);
            }

            try
            {
                //for some reason we have to pass in the input.GetType() to the CloneJson method
                //it was not propigating the type T to the inside of CloneJson in some cases
                var inputValue  = CloneJson(input.GetType(), input);
                var inputMasked = SensitiveData.MaskSensitiveData(inputValue);
                return(JsonConvert.SerializeObject(inputMasked, new StringEnumConverter()));
            }
            catch (Exception ex)
            {
                return("Not able to serialize payload");
            }
        }