[CDRIVER-1335] libbson does not properly serialize the Code type to JSON Created: 16/Jun/16 Updated: 27/Dec/16 Resolved: 11/Nov/16 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | json, libbson |
| Affects Version/s: | None |
| Fix Version/s: | 1.5.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Shane Harvey | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Done | Votes: | 0 |
| Labels: | intern2016 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
The libsson function bson_as_json does not properly serialize the extended JSON type Code. The expected behavior is to output an object with "$code" and "$scope" attributes as demonstrated by json_util from PyMongo
bjson.dumps is a thin wrapper around bson_as_json using the Python C API. |
| Comments |
| Comment by Githook User [ 28/Nov/16 ] | |||
|
Author: {u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}Message: The expected output of bson-javascript-jsonserialize-004.phpt is logically incorrect because of an outstanding bug where Javascript objects are always serialized to BSON code types, irrespective of their scope property. That issue will be fixed by | |||
| Comment by Jeremy Mikola [ 14/Nov/16 ] | |||
Sounds good. I incorrectly assumed this was going to always serialize a "$scope" field. | |||
| Comment by Githook User [ 11/Nov/16 ] | |||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: bson_append_code_with_scope now preserves the "code with scope" type bson_as_json now properly formats BSON "code" and "code with scope" | |||
| Comment by A. Jesse Jiryu Davis [ 09/Nov/16 ] | |||
|
Right, the point of this ticket is we should include empty "$scope", if the BSON type is code with scope, so that the BSON type is properly roundtripped instead of silently changing to code without scope when it's converted to BSON again. | |||
| Comment by Bernie Hackett [ 09/Nov/16 ] | |||
|
I believe this is the format used by mongoexport. PyMongo was recently changed so that explicit empty scope is always output in extended JSON. That matches the behavior of mongoexport and the BSON corpus suite. | |||
| Comment by Jeremy Mikola [ 09/Nov/16 ] | |||
|
jesse: In Slack, you mentioned:
I assume this may be mimicking PyMongo, as Shane shared in the OP:
Is it worth creating an empty "$scope" field when the Extended JSON spec supports both code and code-with-scope types? I'd think "$scope" would simply be omitted if the document is empty or not provided. | |||
| Comment by Bernie Hackett [ 17/Jun/16 ] | |||
|
LOL. I opened | |||
| Comment by A. Jesse Jiryu Davis [ 16/Jun/16 ] | |||
|
Opened | |||
| Comment by A. Jesse Jiryu Davis [ 16/Jun/16 ] | |||
|
Assigning to Ian Boros so he gets some exposure to libbson. | |||
| Comment by Hannes Magnusson [ 16/Jun/16 ] | |||
|
Not documented on https://docs.mongodb.com/manual/reference/mongodb-extended-json/
is indeed what the server does. |