mbraceproject / FsPickler

A fast multi-format message serializer for .NET
http://mbraceproject.github.io/FsPickler/
MIT License
326 stars 51 forks source link

Bug: JsonReader failed to read integers as single and double #84

Closed iskandersierra closed 7 years ago

iskandersierra commented 7 years ago

I detected this case where an integer failed to be recognized as a double. Tried to fix it in this PR. I dont know if the same case would apply to XML or binary formatters.

eiriktsarpalis commented 7 years ago

Hi @iskandersierra and thanks for your contribution. The behaviour you're seeing is by design, since the focus of this library is object transmission across homogenous .NET clusters. It is not intended for deserializing arbitrary json or xml.

iskandersierra commented 7 years ago

Hi @eiriktsarpalis. So are you recommending me not to use FsPickler for parsing input Http/TCP text/binary data?

I'm developing a project where messages are described by some configuration, among others a Pickler to serialize/deserialize the message between microservices. I was thinking on using the same mechanisms to parse input from json/bson/xml comming through an external API. Do you think the second use is not a possible purpose for this library?

By the way I love the simplicity of the Pickler concept. I just tought that parsing could be another role it could assume easily.

eiriktsarpalis commented 7 years ago

I would not recommend it, no. FsPickler expects a specific format when deserializing and will blow up if that format is not respected with no flexibility wrt version tolerance. The pickler pattern is more general than this implementation though, there could be different pickler libraries designed with your requirements in mind.

iskandersierra commented 7 years ago

I see, thanks for the quick feedback. It has been very clarifying on the concept of the purpose of the library. A parser would be mostly a one way function from binary/text to 'T Option (or some other richer result). The Pickler in this lib is intended to be reversible on purpose.

Do you have suggestions on other libraries for this purpose (FParsecis too broad in purpose but too specific for strings). I would like someting like parse: ReadState -> ParseResult<'T> where ReadState abstract the undelying support (text, bin) and ParseResult allowed for partial readings, format errors to be collected.

eiriktsarpalis commented 7 years ago

@iskandersierra I think Newtonsoft is your safest bet for such an application.