rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
230 stars 29 forks source link

Exception on IPAddress serialization #214

Closed jfontsaballs closed 5 years ago

jfontsaballs commented 5 years ago

Hello,

I would like to serialize a System.Net.IPAddress object, but I get a SocketException with error code 10045.

Example code:

var myIpAddress = System.Net.IPAddress.Parse("192.168.1.1");
String s = NetJSON.NetJSON.Serialize(myIpAddress); //Here I get SocketException with ErrorCode=10045

Thank-you.

rpgmaker commented 5 years ago

I will have to make a custom exception for it to support it. so i will suggest doing the following which is going to have been something similar i will have done to wrap it in IL until i have a support for writing custom serializer for non object type.


class IPAddressWrapper {
        public string Value {get; private set;}
        public IPAddress Address => System.Net.IPAddress.Parse(this.Value);
        public IPAddressWrapper(){}
        public IPAddressWrapper(IPAddress ipAddress){
                 this.Value = ipAddress.ToString();
        }
}
var myIpAddress = System.Net.IPAddress.Parse("192.168.1.1");
// Save IPAddress
String s = NetJSON.Serialize(new IPAddressWrapper(myIpAddress));
// Retrieve IPAddress
var ipAddress = NetJSON.Deserialize<IPAddressWrapper>(s).Address;
rpgmaker commented 5 years ago

Let me know if the above makes sense. Thanks

jfontsaballs commented 5 years ago

The solution you suggest is a bit hacky but it makes sense, thank you.

Just started using your serializer for the first time. We decided for it because we are working on a project which makes heavy use of serialization and we are very interested in good performance.

Right now the only feature we miss is the ability to define custom serializers to handle special types, however, thank you for your work.

rpgmaker commented 5 years ago

I have support for custom type serializer. But it is only handle on object type. You can go ahead and create a ticket for me to extend it to all types.

Thanks,