Newtonsoft.Json.dll replacement

Sep 22, 2012 at 8:05 AM

We have replaced most of our web apps to use FastJSON replacing the heavy requirements of Newtonsoft.Json.dll.  Can we accomplish the same with SuperWebSocket?

Sep 22, 2012 at 8:10 AM

After checking the code, I think you can implement your own JsonSubCommand to accomplish it.

I think it's a good idea to open the JSON API in SuperWebSocket.


Sep 22, 2012 at 8:37 AM

I have improved the code to support your requirement. You can override the WebSocketServer tow methods to replace with your own library:


#region JSON serialize/deserialize

        /// <summary>
        /// Serialize the target object by JSON
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public virtual string JsonSerialize(object target)
            return JsonConvert.SerializeObject(target);

        /// <summary>
        /// Deserialize the JSON string to target type object.
        /// </summary>
        /// <param name="json">The json.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public virtual object JsonDeserialize(string json, Type type)
            return JsonConvert.DeserializeObject(json, type);



The change is in master branch, not in 0.6 branch.

If you are using SuperWebSocket 0.6, you must upgrade to SuperWebSocket 0.7 which has not been released, and there would be some changes you need do.

Sep 22, 2012 at 5:05 PM

Thank you very much for fast response & library changes! I will definitely try to download changes & test today. Thanks again.

Sep 28, 2012 at 7:13 PM
Edited Sep 28, 2012 at 7:16 PM

This approach works as far as overriding the JsonDeserialize & JsonSerialize methods with other libraries like fastJSON.  But it still creates dependancies for Newtonsoft.Json.dll.  In VS2010, any project we have referencing SuperWebSocket.dll automatically gets Newtonsoft.Json.dll loaded into the \bin which then gets packaged/published to other websites.  Temporarily, I removed Newtonsoft.Json.dll dependency on SuperWebSocket and redefined these methods:

//HACK:Temporary: Remove all references/dependencies to Newtonsoft.Json.dll
//using Newtonsoft.Json;

//public abstract string JsonSerialize(object target);
public virtual string JsonSerialize(object target) {
//return JsonConvert.SerializeObject(target);
throw new Exception("Must override JsonSerialize!");
//public abstract string JsonDeserialize (object target);
public virtual object JsonDeserialize(string json, Type type) {
//return JsonConvert.DeserializeObject(json, type);
throw new Exception("Must override JsonDeserialize!");

Maybe these methods should be defined as abstract instead of virtual?


I assume something similar will have to be implemented in ver 0.7 to fully remove/replace log4net.dll dependencies?

Sep 29, 2012 at 1:23 PM

Good point, but I have different idea. I think most people don't care which json library they are using. They just want the JSON function working by default, so I prefer to provide default one in SuperWebSocket.


in SuperWebSocket 0.7/SuperSocket 1.5, the logging framework can be replaced.