Block Cascade Json Serealize?
Posted
by CrazyJoe
on Stack Overflow
See other posts from Stack Overflow
or by CrazyJoe
Published on 2010-04-08T16:37:13Z
Indexed on
2010/04/08
16:43 UTC
Read the original article
Hit count: 221
I have this Class:
public class User
{
public string id{ get; set; }
public string name{ get; set; }
public string password { get; set; }
public string email { get; set; }
public bool is_broker { get; set; }
public string branch_id { get; set; }
public string created_at{get; set;}
public string updated_at{get; set;}
public UserGroup UserGroup {get;set;}
public UserAddress UserAddress { get; set; }
public List<UserContact> UserContact {get; set;}
public User()
{
UserGroup = new UserGroup();
UserAddress = new UserAddress();
UserContact = new List<UserContact>();
}
}
I like to Serealize Only properties , how i block serealization of UserGroup, UserAdress, asn UserContact???
This is my Serealization function:
public static string Serealize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
return Encoding.UTF8.GetString(ms.ToArray(), 0,(int)ms.Length);
}
© Stack Overflow or respective owner