public static void anonymoustype() { var jsonParameters = new BJSONParameters { EnableAnonymousTypes = true }; BJSON.RegisterCustomType(typeof(DateTimeOffset), (x) => { return(x.ToString()); }, (x) => { return(DateTimeOffset.Parse(x)); } ); var data = new List <DateTimeOffset>(); data.Add(new DateTimeOffset(DateTime.Now)); var anonTypeWithDateTimeOffset = data.Select(entry => new { DateTimeOffset = entry }).ToList(); var json = BJSON.ToBJSON(anonTypeWithDateTimeOffset.First(), jsonParameters); // this will throw var obj = new { Name = "aa", Age = 42, Code = "007" }; json = BJSON.ToBJSON(obj, jsonParameters); var p = BJSON.Parse(json); Assert.True((p as Dictionary <string, object>).ContainsKey("Name")); BJSON.ClearReflectionCache(); }
public static void statictest() { var s = new InstrumentSettings(); BJSONParameters pa = new BJSONParameters(); pa.UseExtensions = false; InstrumentSettings.isOk = true; InstrumentSettings.isBad = true; var jsonStr = BJSON.ToBJSON(s, pa); var o = BJSON.ToObject <InstrumentSettings>(jsonStr); }
public static void nonstandardkey() { Dictionary <string, object> dict = new Dictionary <string, object>(); dict["With \"Quotes\""] = "With \"Quotes\""; BJSONParameters p = new BJSONParameters(); p.EnableAnonymousTypes = false; p.UseExtensions = false; var s = BJSON.ToBJSON(dict, p); var d = BJSON.ToObject <Dictionary <string, string> >(s); Assert.AreEqual(1, d.Count); Assert.AreEqual("With \"Quotes\"", d.Keys.First()); }
public static void IgnoreAttributes() { var i = new ignore { Age1 = 10, Age2 = 20, Name = "aa" }; var s = fastBinaryJSON.BJSON.ToBJSON(i); var o = fastBinaryJSON.BJSON.ToObject <ignore>(s); Assert.AreEqual(0, o.Age1); i = new ignore1 { Age1 = 10, Age2 = 20, Name = "bb" }; var j = new BJSONParameters(); j.IgnoreAttributes.Add(typeof(ignoreatt)); s = fastBinaryJSON.BJSON.ToBJSON(i, j); var oo = fastBinaryJSON.BJSON.ToObject <ignore1>(s); Assert.AreEqual(0, oo.Age1); Assert.AreEqual(0, oo.Age2); }
internal BJSONSerializer(BJSONParameters param) { _params = param; _MAX_DEPTH = param.SerializerMaxDepth; }
public static void statictest() { var s = new InstrumentSettings(); BJSONParameters pa = new BJSONParameters(); pa.UseExtensions = false; InstrumentSettings.isOk = true; InstrumentSettings.isBad = true; var jsonStr = BJSON.ToBJSON(s, pa); var o = BJSON.ToObject<InstrumentSettings>(jsonStr); }
public static void IgnoreAttributes() { var i = new ignore { Age1 = 10, Age2 = 20, Name = "aa" }; var s = fastBinaryJSON.BJSON.ToBJSON(i); var o = fastBinaryJSON.BJSON.ToObject<ignore>(s); Assert.AreEqual(0, o.Age1); i = new ignore1 { Age1 = 10, Age2 = 20, Name = "bb" }; var j = new BJSONParameters(); j.IgnoreAttributes.Add(typeof(ignoreatt)); s = fastBinaryJSON.BJSON.ToBJSON(i, j); var oo = fastBinaryJSON.BJSON.ToObject<ignore1>(s); Assert.AreEqual(0, oo.Age1); Assert.AreEqual(0, oo.Age2); }
internal BJSONSerializer(BJSONParameters param) { _params = param; }