Exemplo n.º 1
0
        public object Deserialize(string contentType, Stream bodyStream, BindingContext context)
        {
            var deserializedObject = JsonSerializer.DeserializeFromStream(context.DestinationType, bodyStream);

            if (context.DestinationType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Except(context.ValidModelProperties).Any())
            {
                return(CreateObjectWithBlacklistExcluded(context, deserializedObject));
            }

            return(deserializedObject);
        }
Exemplo n.º 2
0
 public void Serialize <TModel>(string contentType, TModel model, Stream outputStream)
 {
     JsonSerializer.SerializeToStream(model, outputStream);
 }
Exemplo n.º 3
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, TransportContext transportContext)
        {
            var task = Task.Factory.StartNew(() => JsonSerializer.SerializeToStream(value, type, writeStream));

            return(task);
        }
Exemplo n.º 4
0
        public override Task <object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
        {
            var task = Task <object> .Factory.StartNew(() => JsonSerializer.DeserializeFromStream(type, readStream));

            return(task);
        }
Exemplo n.º 5
0
 public string Json_DifferenetSerialize()
 {
     return(JsonSerializer.SerializeToString(jsonRoot));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Get JSON string value converted to T
        /// </summary>
        public static T Get <T>(this Dictionary <string, string> map, string key, T defaultValue = default(T))
        {
            string strVal;

            return(map.TryGetValue(key, out strVal) ? JsonSerializer.DeserializeFromString <T>(strVal) : defaultValue);
        }