public void Serialize <TEntity>(TEntity entity, Stream stream) { var s = JsonSerializer.SerializeToString(entity); s = JsvFormatter.Format(s); using (var writer = new StreamWriter(stream)) { writer.Write(s); } }
protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); return(new Formatter(name, type, s => JsonSerializer.DeserializeFromStream(type, s), (o, s) => { using (var writer = new StreamWriter(s)) { writer.WriteLine(); writer.WriteLine(JsvFormatter.Format(JsonSerializer.SerializeToString(o, type))); } })); }
public override string ToString() { return(Item.PrintToString(o => { string details = JsvFormatter.Format(JsonSerializer.SerializeToString(o)); string description; if (Describe.TryDescribe(o, out description)) { return "\r\n" + Indent(description) + "\r\n\r\n" + details; } return details; })); }
protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); return(new Formatter(name, s => JsonSerializer.DeserializeFromStream(type, s), (o, s) => { using (var writer = new StreamWriter(s)) { writer.WriteLine(); writer.WriteLine(JsvFormatter.Format(JsonSerializer.SerializeToString(o, type))); } })); //var formatter = RuntimeTypeModel.Default.CreateFormatter(type); //return new Formatter(name, formatter.Deserialize, (o, stream) => formatter.Serialize(stream, o)); }
public static string SerializeAndFormat <T>(this T instance) { var fn = instance as Delegate; if (fn != null) { return(Dump(fn)); } var dtoStr = !HasCircularReferences(instance) ? SerializeToString(instance) : SerializeToString(instance.ToSafePartialObjectDictionary()); var formatStr = JsvFormatter.Format(dtoStr); return(formatStr); }
public void Should_be_able_to_serialize_responses_to_json( object response, string serializedContent) { "Given a response of type {0}" .Given(() => { }); "When serializing to json" .When(() => serializedContent = Serialize(response, (o, stream) => new ServiceStackJsonFormatter().WriteToStream(o.GetType(), o, stream, new StringContent("")))); "Then should have serialized successfully".Then(() => { Debug.Write(JsvFormatter.Format(serializedContent).Replace("\t", " ")); serializedContent.Should().NotBeNullOrEmpty(); }); }
public override string ToString() { return(Item.PrintToString(o => { var details = JsvFormatter.Format(JsonSerializer.SerializeToString(o)); var ie = o as IEvent <IIdentity>; //if (ie != null) //{ // details = details + "\r\n From:" + IdentityConvert.ToPartitionedName(ie.Id); //} string description; if (Describe.TryDescribe(o, out description)) { return "\r\n" + Indent(description) + "\r\n\r\n" + details; } return details; })); }
public string GetView() { Maybe <TView> possibleView; if (this.Key != null) { possibleView = this.Client.GetView <TView>(this.Key); } else { possibleView = this.Client.GetSingleton <TView>(); } if (possibleView.HasValue) { return(JsvFormatter.Format(TypeSerializer.SerializeToString(possibleView.Value))); } else { return("View does not exist"); } }
static void DescribeMessage(StringBuilder builder, ImmutableEnvelope context) { builder.AppendLine(context.PrintToString(o => JsvFormatter.Format(JsonSerializer.SerializeToString(o)))); }
public void BindMessage(Type messageType, object instance) { MessageType = messageType; richTextBox1.Text = JsvFormatter.Format(JsonSerializer.SerializeToString(instance)); }