Esempio n. 1
0
 public static T Deserialize <T>(Stream s, SafeJsonTypeSerialization.JsonKnownTypesBinder binder = null)
 {
     using (StreamReader reader = new StreamReader(s))
         using (JsonTextReader jsonReader = new JsonTextReader(reader))
         {
             JsonSerializer ser = new JsonSerializer()
             {
                 SerializationBinder = binder ?? new SafeJsonTypeSerialization.JsonKnownTypesBinder()
             };
             return(ser.Deserialize <T>(jsonReader));
         }
 }
Esempio n. 2
0
 public static void Serialize(object value, Stream s, Formatting f = Formatting.None, SafeJsonTypeSerialization.JsonKnownTypesBinder binder = null)
 {
     using (StreamWriter writer = new StreamWriter(s))
         using (JsonTextWriter jsonWriter = new JsonTextWriter(writer))
         {
             JsonSerializer ser = new JsonSerializer
             {
                 Formatting          = f,
                 SerializationBinder = binder ?? new SafeJsonTypeSerialization.JsonKnownTypesBinder()
             };
             ser.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
             ser.Serialize(jsonWriter, value);
             jsonWriter.Flush();
         }
 }