-
Notifications
You must be signed in to change notification settings - Fork 8
Allow data as json #4
base: v1.0
Are you sure you want to change the base?
Conversation
|
Thanks for the PR! It makes sense to have an easy way of sending raw data using the library but I don't think the json check is the correct way. The way it's written will break on py3 as the input to the easier |
|
Python states EAFP: Therefore it is safer, faster and cleaner having |
|
What we really need to check is that it's something that can transmitted through the urllib stuff which is limited to str/bytes because of the digest. Checking for valid json might be a nice addition but ultimately not needed imo But the real problem is that json.loads will actually fail for the specific type we need it to be for py3 (bytes not str). I guess you could change 88 to be |
|
If |
|
|
|
I'm happy with any kind of alternative implementation accepting a native JSON string. Please keep in mind, that my REST serializer stores its data as |
|
With this implementation is impossible to find a "jsonblob" object to pass that will actually work. give it a str and I get your use case and agree it would be good to be able to pass in a raw payload. I don't really mind either way if it's str or bytes that the proper type to give but at least one should work and something eq between 2 and 3 like "unicode or str"/str or "encoded str"/bytes. What format are you keeping the REST response in? |
|
Sure, I could do the conversion to JSON only if
This is similar to a Python dict, but may include OrderedDict elements. Therefore the JSON encoder/decoder, as shipped with Django-RESTframework, serializes/deserializes that data in the correct order. Normal Python dicts get resorted in arbitrary order. |
|
Something like that could work but is perhaps an even worse violation of second guessing what the json module can encode/decode. Perhaps it would be better to add a more explicit way of bypassing the encoding step say by a "body" option to complement the existing "data" option. re the format I was more wondering if the value you are sending in is utf-8 encoded already or in "unicode" |
|
a17dcc0 is another approach to solve this. An alternative would be to allow to override the |
|
Will that really work? |
|
Ups, only on but not on that's weird. How about |
|
I think that would be fine |
…g-orders to v2.0 * commit '4020d34b10d5e09577e9240fd85b4556c19ab30c': Making code examples more aligned to other SDKs Updating copyright headers date Fixing code examples Added UTF-8 file header Adding better support for JSON error messages Fixed the recurring_test v2.0.0 remove unused matcher use upstream mock matcher remove changelog add examples for recurring orders update existing examples add resource objects for recurring orders add test requirements to test-requirements.txt
I use a REST service to serialize the cart. This REST service returns the carts content serialized in JSON format. Therefore I would have to convert it back to a Python dict, which doesn't make sense, since later it is has to be converted to JSON anyway.
Therefore I'd like to add a check, which bypasses the serialization, if the
dataobject already is valid JSON.