Please, let me explain once more what want.

I need a JSON codec (serializer-deserializer), which can preserve its input on 
its output. After some thought it seems to be really concerning only the 
floats. (The attempt to generalize this should be regarded as secondary - just 
suggestion subject to comments).

What you, Andrew and possibly Chris have probably understood is that I was 
asking for a JSON codec which would ensure the same bit to bit (or byte to 
byte) output with any other JSON codec out there. This never was my point, as, 
in my first post, in this thread, I already gave an example of two different 
serializers which give different results and invalidate directly such a 
request. And, as Chris pointed out in one of his replies, it is simply matter 
of choice and none is either "right" or "wrong".

Second, the fact that the JSON codec (I am looking for) should be able to 
preserve its inputs in its outputs byte-to-byte does not necessarily mean that 
the (default) standard implementation must do that. As, again using the same 
example I gave above, I am fine with default implementation, which chooses 
platform native binary float for the JSON float representation and is as such 
subject to the consequences already discussed here.

The only thing what my "request" requires from the standard module is to allow 
serialize decimal.Decimal or, in broader scope, some custom type in a way that 
it can preserve its input in its output byte-to-byte. And this and only this is 
exactly the kind of byte-to-byte precision I need from the implementation. Or 
better say I need an adequate support from the standard implementation that it 
should be possible.

After thinking it through, it seems to me that the current implementation with 
JSONEncoder.default override satisfies this requirement for any custom type, 
except decimal.Decimal, because of how it handles the custom value provided by 
custom serializer and because decimal.Decimal is in fact a representation of 
the native JSON type (float).

There is no way to serialize the float, which was deserialized into 
decimal.Decimal as a float again and have the exactly same value (literally) in 
the output as was in the input.

Serializing it into custom map or a string might acceptable for some other 
application (though one would wonder why to do that to something which is by 
nature a native JSON type with perfectly valid representation of its own), but 
is not acceptable in my case for reasons stated above.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7HTES3EHGB2NMDTSGLN5HZCBYGX5FB74/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to