Esempio n. 1
0
        public static void TestSerializers()
        {
            //var authenticatingJson = "{\"state\":\"authenticating\",\"scheme\":\"plain\",\"authentication\":{\"password\":\"bXlwYXNzd29yZA==\"},\"id\":\"458f5c19-5655-47c9-8f67-a064c5f9f9d6\",\"from\":\"[email protected]/NOTEBIRES\"}";

            var commandJson = "{\"type\":\"application/vnd.lime.roster+json\",\"resource\":{\"contacts\":[{\"identity\":\"[email protected]\",\"name\":\"gbt9g5eioc9dqkb86sonim2sjvhekexokftjhr6zsrpvnscyzh\",\"isPending\":true,\"shareAccountInfo\":false,\"sharePresence\":true},{\"identity\":\"[email protected]\",\"name\":\"110pwz406hf0ssodndz9wyag1kartfh1z177ql79q28c69cgv4\",\"sharePresence\":false},{\"identity\":\"[email protected]\",\"name\":\"uqxbfzt3z8k1i46yi655d4h5xwldvgbs7lveh5egk4n2k6c3qs\",\"isPending\":true,\"sharePresence\":false}]},\"method\":\"get\",\"status\":\"success\",\"id\":\"b625b0f9-c187-4858-a79b-d9b82088ad3e\",\"from\":\"[email protected]/j1rn1\",\"pp\":\"[email protected]/963f4\",\"to\":\"[email protected]/pqv25\",\"metadata\":{\"randomString1\":\"70bjn6b6g6zxvscyn77brxihkv9j3v5bpa73a6g39je640yme8\",\"randomString2\":\"v95emks48261dvaxhvuiyr0dbislmu7wf495glxwlf7o6ift5g\"}}";

            var json = commandJson;

            var serializer1 = new EnvelopeSerializer();
            var serializer2 = new Lime.Protocol.Serialization.Newtonsoft.JsonNetSerializer();
            //var serializer3 = new Lime.Protocol.Serialization.ServiceStack.ServiceStackSerializer();


            Envelope envelope1 = null, envelope2 = null, envelope3 = null;

            int count;

            do
            {
                System.Console.Write("Serialization count: ");
            } while (!int.TryParse(System.Console.ReadLine(), out count));
                        
            System.Console.WriteLine("Deserialization:");

            envelope1 = ExecuteDeserialization(serializer1, json, count);
            envelope2 = ExecuteDeserialization(serializer2, json, count);
            //envelope3 = ExecuteDeserialization(serializer3, json, count);

            // netwonsoft is the reference serializer
            var json1 = serializer2.Serialize(envelope1);
            var json2 = serializer2.Serialize(envelope2);
            var json3 = serializer2.Serialize(envelope3);

            if (json1 == json2 && json2 == json3)
            {
                System.Console.WriteLine("All deserialized types are equals");
            }
            else
            {
                System.Console.WriteLine("Deserialized types NOT equals: ");
            }

            var envelope = envelope1;

            System.Console.WriteLine("Serialization:");

            json1 = ExecuteSerialization(serializer1, envelope, count);
            json2 = ExecuteSerialization(serializer2, envelope, count);
            //json3 = ExecuteSerialization(serializer3, envelope, count);

            if (json1 == json2 && json2 == json3)
            {
                System.Console.WriteLine("All serialized types are equals");
            }
            else
            {
                System.Console.WriteLine("Serialized types are NOT equals: ");
            }

            System.Console.Read();
        }
Esempio n. 2
0
 public DocumentSerializer(IDocumentTypeResolver documentTypeResolver)
 {
     _documentTypeResolver = documentTypeResolver;
     _settings             = EnvelopeSerializer.CreateSettings(documentTypeResolver);
     _jsonSerializer       = JsonSerializer.Create(_settings);
 }