public static string ToJsonString(this IJsonSerializable jsonSerializable) { if (ReferenceEquals(jsonSerializable, null)) { return(string.Empty); } var stringBuilder = new StringBuilder(); using (var writer = JSON.GetWriter(new StringWriter(stringBuilder))) { try { jsonSerializable.ToJson(writer); } catch (Exception ex) { if (Log != null) { Log.WarnFormat( "Unable to serialize component: {0} - {1}", jsonSerializable.GetType().Name, ex.Message ); } throw; } } return(stringBuilder.ToString()); }
public static TRes PackMessage <TRes>(string key, IJsonSerializable obj) where TRes : IDictionary <string, object> { var result = Activator.CreateInstance <TRes>(); result.Add(key, obj.ToJson()); return(result); }
protected virtual void WriteValue(IJsonSerializable obj) { string json = obj.ToJson(); Debug.Assert(json != null); this.WriteCore(json, false); }
public static string GetJsonForSymbol(IJsonSerializable serializable) { if (serializable == null) { return(null); } string json = serializable.ToJson(); return(json); }
public static void SerializeToJson(IJsonSerializable data, string path) { using (FileStream fileStream = new FileStream(path, 2)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(data.ToJson()); } } }
public static string ToJson(this IJsonSerializable jsonConfig) { var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; jsonConfig.ToJson(writer); } return(sb.ToString()); }
/// <summary> /// Creates the json request. /// </summary> /// <returns></returns> internal JsonObject CreateJsonRequest() { IJsonSerializable serializableRequest = this as IJsonSerializable; if (serializableRequest == null) { throw new JsonSerializationNotImplementedException(); } JsonObject jsonRequest = new JsonObject(); jsonRequest.Add("Header", this.CreateJsonHeaders()); jsonRequest.Add("Body", serializableRequest.ToJson(service)); return(jsonRequest); }
public static JsonArray FromArray <T>(T[] array) { int count = array.Length; JsonArray result = new JsonArray(count); bool serialize = typeof(IJsonSerializable).IsAssignableFrom(typeof(T)); for (int i = 0; i < count; i++) { if (serialize) { IJsonSerializable srz = (IJsonSerializable)array[i]; result._list.Add(srz.ToJson()); } else { result._list.Add(array[i]); } } return(result); }
public void Value(IJsonSerializable s) { CommaCheck(); m_w.Write(s.ToJson()); }
public static object Write(IJsonSerializable val) { return(val.ToJson()); }
public static string ToJson(this IJsonSerializable x, bool indent = false) { return(x.ToJson(new JsonSerializationOptions { UseIndentation = indent })); }
public static string Serialize(IJsonSerializable obj) { return(JsonSerializer.Serialize(obj.ToJson(), new SerializerConfig())); }
public static string Serialize(IJsonSerializable obj, SerializerConfig config) { return(JsonSerializer.Serialize(obj.ToJson(), config)); }
public void Put(string key, IJsonSerializable value) { _dict.Add(key, value.ToJson()); }
public static string GetJsonForSymbol(IJsonSerializable serializable) { if (serializable == null) return null; string json = serializable.ToJson(); return json; }