/// <summary> /// Create a binary json representation for an object with parameter override on this call /// </summary> /// <param name="obj"></param> /// <param name="param"></param> /// <returns></returns> public static byte[] ToBJSON(object obj, BJSONParameters param) { param.FixValues(); Type t = null; if (obj == null) { return new byte[] { TOKENS.NULL } } ; if (obj.GetType().IsGenericType) { t = Reflection.Instance.GetGenericTypeDefinition(obj.GetType());// obj.GetType().GetGenericTypeDefinition(); } if (t == typeof(Dictionary <,>) || t == typeof(List <>)) { param.UsingGlobalTypes = false; } // FEATURE : enable extensions when you can deserialize anon types if (param.EnableAnonymousTypes) { param.UseExtensions = false; param.UsingGlobalTypes = false; } return(new BJSONSerializer(param).ConvertToBJSON(obj)); }
public object Parse(byte[] json) { _params = Parameters; _params.FixValues(); _globalTypes = _params.UsingGlobalTypes; return(new BJsonParser(json, _params.UseUTCtimes).Decode()); }
public object FillObject(object input, byte[] json) { _params.FixValues(); Dictionary <string, object> ht = new BJsonParser(json, _params.UseUTCDateTime, _params.v1_4TypedArray).Decode() as Dictionary <string, object>; if (ht == null) { return(null); } return(ParseDictionary(ht, null, input.GetType(), input)); }
public object ToObject(byte[] json, Type type) { _params.FixValues(); Type t = null; if (type != null && type.IsGenericType) { t = Reflection.Instance.GetGenericTypeDefinition(type);// type.GetGenericTypeDefinition(); } if (t == typeof(Dictionary <,>) || t == typeof(List <>)) { _params.UsingGlobalTypes = false; } _globalTypes = _params.UsingGlobalTypes; var o = new BJsonParser(json, _params.UseUTCDateTime).Decode(); #if !SILVERLIGHT if (type != null && type == typeof(DataSet)) { return(CreateDataset(o as Dictionary <string, object>, null)); } if (type != null && type == typeof(DataTable)) { return(CreateDataTable(o as Dictionary <string, object>, null)); } #endif if (o is typedarray) { return(ParseTypedArray(new Dictionary <string, object>(), o)); } if (o is IDictionary) { if (type != null && t == typeof(Dictionary <,>)) // deserialize a dictionary { return(RootDictionary(o, type)); } else // deserialize an object { return(ParseDictionary(o as Dictionary <string, object>, null, type, null)); } } if (o is List <object> ) { if (type != null && t == typeof(Dictionary <,>)) // kv format { return(RootDictionary(o, type)); } if (type != null && t == typeof(List <>)) // deserialize to generic list { return(RootList(o, type)); } if (type == typeof(Hashtable)) { return(RootHashTable((List <object>)o)); } else if (type == null) { List <object> l = (List <object>)o; if (l.Count > 0 && l[0].GetType() == typeof(Dictionary <string, object>)) { Dictionary <string, object> globals = new Dictionary <string, object>(); List <object> op = new List <object>(); // try to get $types foreach (var i in l) { op.Add(ParseDictionary((Dictionary <string, object>)i, globals, null, null)); } return(op); } return(l.ToArray()); } } else if (type != null && o.GetType() != type) { return(ChangeType(o, type)); } return(o); }
/// <summary> /// Create an object from the json with parameter override on this call /// </summary> /// <param name="json"></param> /// <param name="param"></param> /// <returns></returns> public static object ToObject(byte[] json, BJSONParameters param) { param.FixValues(); return(new deserializer(param).ToObject(json, null)); }
public object ToObject(byte[] json, Type type) { _params.FixValues(); Type t = null; if (type != null && type.IsGenericType) { t = Reflection.Instance.GetGenericTypeDefinition(type);// type.GetGenericTypeDefinition(); } if (t == typeof(Dictionary <,>) || t == typeof(List <>)) { _params.UsingGlobalTypes = false; } _globalTypes = _params.UsingGlobalTypes; var o = new BJsonParser(json, _params.UseUTCDateTime).Decode(); #if !SILVERLIGHT if (type != null && type == typeof(DataSet)) { return(CreateDataset(o as Dictionary <string, object>, null)); } if (type != null && type == typeof(DataTable)) { return(CreateDataTable(o as Dictionary <string, object>, null)); } #endif if (o is IDictionary) { if (type != null && t == typeof(Dictionary <,>)) // deserialize a dictionary { return(RootDictionary(o, type)); } else // deserialize an object { return(ParseDictionary(o as Dictionary <string, object>, null, type, null)); } } if (o is List <object> ) { if (type != null && t == typeof(Dictionary <,>)) // kv format { return(RootDictionary(o, type)); } if (type != null && t == typeof(List <>)) // deserialize to generic list { return(RootList(o, type)); } if (type == typeof(Hashtable)) { return(RootHashTable((List <object>)o)); } else { return((o as List <object>).ToArray()); } } return(o); }