public void FastSerializer_Dictionary_Custom_ArgumentChecking() { var ser = FastJsonSerializerFactory.CreateSerializer <IDictionary <string, int> >(provider: null, FastJsonConcurrencyMode.SingleThreaded); Assert.ThrowsException <InvalidOperationException>(() => ser.Serialize(new NullableDictionary <string, int> { { null, 42 } })); }
public Serialize() { _nucleusSerializer = FastJsonSerializerFactory.CreateSerializer <Person>(DefaultNameProvider.Instance, FastJsonConcurrencyMode.SingleThreaded); _jsonSerializer = Newtonsoft.Json.JsonSerializer.CreateDefault(); _person = new Person { Name = "Bart", Age = 21 }; }
public void FastSerializer_Any_ArgumentChecking() { var ser = FastJsonSerializerFactory.CreateSerializer <object>(provider: null, FastJsonConcurrencyMode.SingleThreaded); Assert.ThrowsException <NotSupportedException>(() => ser.Serialize(new int[1, 1])); #if !NO_IO Assert.ThrowsException <NotSupportedException>(() => ser.Serialize(new int[1, 1], new System.IO.StringWriter())); #endif }
public void FastDeserializer_ArgumentChecking() { var des = FastJsonSerializerFactory.CreateDeserializer <int>(resolver: null, FastJsonConcurrencyMode.SingleThreaded); Assert.ThrowsException <ArgumentNullException>(() => des.Deserialize(default(string))); #if !NO_IO Assert.ThrowsException <ArgumentNullException>(() => des.Deserialize(default(System.IO.TextReader))); #endif Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => des.Deserialize("42a")); Assert.ThrowsException <ArgumentNullException>(() => FastJsonSerializerFactory.CreateDeserializer <int>(resolver: null, settings: null)); }
private static void AssertDeserializeFails <T>(params string[] inputs) { var des = FastJsonSerializerFactory.CreateDeserializer <T>(resolver: null, FastJsonConcurrencyMode.SingleThreaded); foreach (var json in inputs) { Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => des.Deserialize(json)); #if !NO_IO Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => des.Deserialize(new System.IO.StringReader(json))); #endif } }
private static void AssertSerialize <T>(Asserts <T> asserts) { foreach (var ser in new[] { FastJsonSerializerFactory.CreateSerializer <T>(provider: null, FastJsonConcurrencyMode.SingleThreaded), FastJsonSerializerFactory.CreateSerializer <T>(provider: null, FastJsonConcurrencyMode.ThreadSafe), }) { foreach (var kv in asserts) { Assert.AreEqual(kv.Value, ser.Serialize(kv.Key)); } if (asserts._null != null) { Assert.AreEqual(asserts._null, ser.Serialize(default));
public void FastSerializer_PersonWithParent_CycleDetection() { var ser = FastJsonSerializerFactory.CreateSerializer <PersonWithParent>(provider: null, FastJsonConcurrencyMode.SingleThreaded); var cyclic1 = new PersonWithParent(); cyclic1.Parent = cyclic1; var cyclic2 = new PersonWithParent { Parent = new PersonWithParent() }; cyclic2.Parent.Parent = cyclic2; Assert.ThrowsException <InvalidOperationException>(() => ser.Serialize(cyclic1)); Assert.ThrowsException <InvalidOperationException>(() => ser.Serialize(cyclic2)); }
private static void AssertDeserialize <T>(Asserts <T> asserts, INameResolver resolver) { foreach (var des in new[] { FastJsonSerializerFactory.CreateDeserializer <T>(resolver, FastJsonConcurrencyMode.SingleThreaded), FastJsonSerializerFactory.CreateDeserializer <T>(resolver, FastJsonConcurrencyMode.ThreadSafe), }) { foreach (var kv in asserts) { Assert.AreEqual(kv.Value, des.Deserialize(kv.Key)); #if !NO_IO Assert.AreEqual(kv.Value, des.Deserialize(new System.IO.StringReader(kv.Key))); #endif } } }
private static void AssertDeserialize <T>(Asserts <T> asserts, Func <T, T, bool> assert) { foreach (var des in new[] { FastJsonSerializerFactory.CreateDeserializer <T>(resolver: null, FastJsonConcurrencyMode.SingleThreaded), FastJsonSerializerFactory.CreateDeserializer <T>(resolver: null, FastJsonConcurrencyMode.ThreadSafe), }) { foreach (var kv in asserts) { Assert.IsTrue(assert(kv.Value, des.Deserialize(kv.Key))); #if !NO_IO Assert.IsTrue(assert(kv.Value, des.Deserialize(new System.IO.StringReader(kv.Key)))); #endif } } }
private static object CreateSerializer <T>() { return(FastJsonSerializerFactory.CreateSerializer <T>(NameProvider.Instance, FastJsonConcurrencyMode.ThreadSafe)); }
public void FastSerializer_ArgumentChecking() { Assert.ThrowsException <ArgumentNullException>(() => FastJsonSerializerFactory.CreateSerializer <int>(provider: null, settings: null)); }
public Deserialize() { _nucleusDeserializer = FastJsonSerializerFactory.CreateDeserializer <Person>(DefaultNameResolver.Instance, FastJsonConcurrencyMode.SingleThreaded); _jsonDeserializer = Newtonsoft.Json.JsonSerializer.CreateDefault(); _json = "{ \"Name\": \"Bart\", \"Age\": 21 }"; }
public Deserializer() { _deserializer = FastJsonSerializerFactory.CreateDeserializer <T>(NameResolver.Instance, FastJsonConcurrencyMode.ThreadSafe); }
public Serializer() { _serializer = FastJsonSerializerFactory.CreateSerializer <T>(NameProvider.Instance, FastJsonConcurrencyMode.ThreadSafe); }