예제 #1
0
        public void Deserialize_Video_Test_Basic()
        {
            JavaScriptSerializer         serializer = BrightcoveSerializerFactory.GetSerializer();
            IDictionary <string, object> dictionary = new Dictionary <string, object>();
            var testrenditionCollection             = new BrightcoveItemCollection <BrightcoveRendition>();
            var testrendition = new BrightcoveRendition();

            testrendition.ControllerType = ControllerType.AkamaiHd;
            testrenditionCollection.Add(testrendition);
            dictionary.Add("renditions", testrenditionCollection);

            var renditions =
                serializer.ConvertToType <BrightcoveItemCollection <BrightcoveRendition> >(dictionary["renditions"]);

            Assert.That(renditions[0].ControllerType, Is.EqualTo(ControllerType.AkamaiHd));
        }
        /// <summary>
        /// Converts an <see cref="IDictionary{String, Object}"/> to a JSON string.
        /// </summary>
        /// <param name="dict">The <see cref="IDictionary{String, Object}"/> to convert.</param>
        /// <returns>A JSON string.</returns>
        public static string ToJson(this IDictionary <string, object> dict)
        {
            JavaScriptSerializer serializer = BrightcoveSerializerFactory.GetSerializer();

            return(serializer.Serialize(dict));
        }
예제 #3
0
        /// <summary>
        /// Converts a wrapper model class into the corresponding JSON representation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected static string SerializeJson <T>(T obj) where T : IJavaScriptConvertable
        {
            JavaScriptSerializer serializer = BrightcoveSerializerFactory.GetSerializer();

            return(serializer.Serialize(obj));
        }
예제 #4
0
        /// <summary>
        /// Converts json retrieved from Brightcove to an instance of the corresponding wrapper model class.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <returns></returns>
        protected static T DeserializeJson <T>(string json) where T : IJavaScriptConvertable
        {
            JavaScriptSerializer serializer = BrightcoveSerializerFactory.GetSerializer();

            return(serializer.Deserialize <T>(json));
        }