Skip to content

Commit 692bab2

Browse files
authored
CDRIVER-5700 deprecate bson_as_json and bson_array_as_json (#1776)
* deprecate `bson_as_json` and `bson_array_as_json` * add `bson_as_legacy_extended_json` and `bson_array_as_legacy_extended_json` as non-deprecated alternatives * remove use of deprecated calls * document libbson's Legacy Extended JSON
1 parent e24fa14 commit 692bab2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+763
-226
lines changed

.evergreen/scripts/compile-libmongocrypt.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ compile_libmongocrypt() {
1010
# `.evergreen/scripts/kms-divergence-check.sh` to ensure that there is no
1111
# divergence in the copied files.
1212

13-
# TODO: once 1.12.0 is released (containing MONGOCRYPT-599) replace the following with:
13+
# TODO: once 1.12.0 is released (containing de69cc91e1574e8861cd0ceb4bb866cc02a53d6b) replace the following with:
1414
# git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.12.0 || return
1515
{
1616
git clone -q https://github.com/mongodb/libmongocrypt || return
17-
# Check out commit containing MONGOCRYPT-599
18-
git -C libmongocrypt checkout 7aeaec4ae1369c7d3c5b3aea6f1da35c5e9478b0
17+
git -C libmongocrypt checkout de69cc91e1574e8861cd0ceb4bb866cc02a53d6b
1918
}
2019

2120
declare -a crypt_cmake_flags=(

src/libbson/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ if (ENABLE_EXAMPLES)
295295
add_example (json-to-bson examples/json-to-bson.c)
296296
add_example (bson-check-depth examples/bson-check-depth.c)
297297
add_example (creating examples/creating.c)
298+
add_example (extended-json examples/extended-json.c)
298299
endif () # ENABLE_EXAMPLES
299300

300301

src/libbson/NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Deprecated:
77
* Compiling with `BSON_MEMCHECK` defined is deprecated.
88
* `bson_in_range_*` and `bson_cmp_*` functions.
99
* `bson_atomic_*` and `bson_thrd_yield` functions.
10+
* `bson_as_json` and `bson_array_as_json` are deprecated due to producing non-portable Legacy Extended JSON. Prefer Canonical Extended JSON or Relaxed Extended JSON for portability. To continue using Legacy Extended JSON, use `bson_as_legacy_extended_json` and `bson_array_as_legacy_extended_json`.
1011

1112
libbson 1.28.1
1213
==============

src/libbson/doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ API Reference
2626
bson_get_monotonic_time
2727
bson_memory
2828
version
29+
legacy_extended_json

src/libbson/doc/bson_array_as_canonical_extended_json.rst

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Parameters
2020
Description
2121
-----------
2222

23-
The :symbol:`bson_array_as_canonical_extended_json()` encodes ``bson`` as a UTF-8 string in the canonical `MongoDB Extended JSON format`_, except the outermost element is encoded as a JSON array, rather than a JSON document.
23+
:symbol:`bson_array_as_canonical_extended_json()` encodes ``bson`` as a UTF-8 string in Canonical Extended JSON.
24+
The outermost element is encoded as a JSON array (``[ ... ]``), rather than a JSON document (``{ ... }``).
25+
See `MongoDB Extended JSON format`_ for a description of Extended JSON formats.
2426

2527
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result.
2628

@@ -36,31 +38,11 @@ Upon failure, NULL is returned.
3638
Example
3739
-------
3840

39-
.. code-block:: c
40-
41-
#include <bson/bson.h>
42-
43-
int main ()
44-
{
45-
bson_t bson;
46-
char *str;
47-
48-
bson_init (&bson);
49-
/* BSON array is a normal BSON document with integer values for the keys,
50-
* starting with 0 and continuing sequentially
51-
*/
52-
BSON_APPEND_INT32 (&bson, "0", 1);
53-
BSON_APPEND_UTF8 (&bson, "1", "bar");
54-
55-
str = bson_array_as_canonical_extended_json (&bson, NULL);
56-
/* Prints
57-
* [ { "$numberInt" : 1 }, "bar" ]
58-
*/
59-
printf ("%s\n", str);
60-
bson_free (str);
61-
62-
bson_destroy (&bson);
63-
}
41+
.. literalinclude:: ../examples/extended-json.c
42+
:language: c
43+
:start-after: // bson_array_as_canonical_extended_json ... begin
44+
:end-before: // bson_array_as_canonical_extended_json ... end
45+
:dedent: 6
6446

6547

6648
.. only:: html

src/libbson/doc/bson_array_as_json.rst

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
bson_array_as_json()
44
====================
55

6+
.. warning::
7+
.. deprecated:: 1.29.0
8+
9+
This function is deprecated and should not be used in new code.
10+
611
Synopsis
712
--------
813

914
.. code-block:: c
1015
1116
char *
12-
bson_array_as_json (const bson_t *bson, size_t *length);
17+
bson_array_as_json (const bson_t *bson, size_t *length) BSON_GNUC_DEPRECATED_FOR (bson_array_as_legacy_extended_json);
1318
1419
Parameters
1520
----------
@@ -20,14 +25,12 @@ Parameters
2025
Description
2126
-----------
2227

23-
The :symbol:`bson_array_as_json()` function shall encode ``bson`` as a UTF-8
24-
string using libbson's legacy JSON format, except the outermost element is
25-
encoded as a JSON array, rather than a JSON document. This function is
26-
superseded by :symbol:`bson_array_as_canonical_extended_json()` and
27-
:symbol:`bson_array_as_relaxed_extended_json()`, which use the same
28-
`MongoDB Extended JSON format`_ as all other MongoDB drivers.
29-
The caller is responsible for freeing the resulting UTF-8 encoded string by
30-
calling :symbol:`bson_free()` with the result.
28+
:symbol:`bson_array_as_json()` encodes ``bson`` as a UTF-8 string using :doc:`libbson's Legacy Extended JSON <legacy_extended_json>`.
29+
The outermost element is encoded as a JSON array (``[ ... ]``), rather than a JSON document (``{ ... }``).
30+
This function is superseded by :symbol:`bson_array_as_canonical_extended_json()` and :symbol:`bson_array_as_relaxed_extended_json()`, which use the same `MongoDB Extended JSON format`_ as all other MongoDB drivers.
31+
To continue producing Legacy Extended JSON, :symbol:`bson_array_as_legacy_extended_json()` may be used.
32+
33+
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result.
3134

3235
If non-NULL, ``length`` will be set to the length of the result in bytes.
3336

@@ -38,36 +41,6 @@ If successful, a newly allocated UTF-8 encoded string and ``length`` is set.
3841

3942
Upon failure, NULL is returned.
4043

41-
Example
42-
-------
43-
44-
.. code-block:: c
45-
46-
#include <bson/bson.h>
47-
48-
int main ()
49-
{
50-
bson_t bson;
51-
char *str;
52-
53-
bson_init (&bson);
54-
/* BSON array is a normal BSON document with integer values for the keys,
55-
* starting with 0 and continuing sequentially
56-
*/
57-
BSON_APPEND_UTF8 (&bson, "0", "foo");
58-
BSON_APPEND_UTF8 (&bson, "1", "bar");
59-
60-
str = bson_array_as_json (&bson, NULL);
61-
/* Prints
62-
* [ "foo", "bar" ]
63-
*/
64-
printf ("%s\n", str);
65-
bson_free (str);
66-
67-
bson_destroy (&bson);
68-
}
69-
70-
7144
.. only:: html
7245

7346
.. include:: includes/seealso/bson-as-json.txt
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:man_page: bson_array_as_legacy_extended_json
2+
3+
bson_array_as_legacy_extended_json()
4+
====================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
char *
12+
bson_array_as_legacy_extended_json (const bson_t *bson, size_t *length)
13+
14+
Parameters
15+
----------
16+
17+
* ``bson``: A :symbol:`bson_t`.
18+
* ``length``: An optional location for the length of the resulting string.
19+
20+
Description
21+
-----------
22+
23+
:symbol:`bson_array_as_legacy_extended_json()` encodes ``bson`` as a UTF-8 string using :doc:`libbson's Legacy Extended JSON <legacy_extended_json>`.
24+
The outermost element is encoded as a JSON array (``[ ... ]``), rather than a JSON document (``{ ... }``).
25+
This function is superseded by :symbol:`bson_array_as_canonical_extended_json()` and :symbol:`bson_array_as_relaxed_extended_json()`, which use the same `MongoDB Extended JSON format`_ as all other MongoDB drivers.
26+
27+
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result.
28+
29+
If non-NULL, ``length`` will be set to the length of the result in bytes.
30+
31+
Returns
32+
-------
33+
34+
If successful, a newly allocated UTF-8 encoded string and ``length`` is set.
35+
36+
Upon failure, NULL is returned.
37+
38+
Example
39+
-------
40+
41+
.. literalinclude:: ../examples/extended-json.c
42+
:language: c
43+
:start-after: // bson_array_as_legacy_extended_json ... begin
44+
:end-before: // bson_array_as_legacy_extended_json ... end
45+
:dedent: 6
46+
47+
.. only:: html
48+
49+
.. include:: includes/seealso/bson-as-json.txt
50+
51+
.. _MongoDB Extended JSON format: https://github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md

src/libbson/doc/bson_array_as_relaxed_extended_json.rst

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Parameters
2020
Description
2121
-----------
2222

23-
The :symbol:`bson_as_relaxed_extended_json()` encodes ``bson`` as a UTF-8 string in the relaxed `MongoDB Extended JSON format`_, except the outermost element is encoded as a JSON array, rather than a JSON document.
23+
:symbol:`bson_as_relaxed_extended_json()` encodes ``bson`` as a UTF-8 string in the Relaxed Extended JSON.
24+
The outermost element is encoded as a JSON array (``[ ... ]``), rather than a JSON document (``{ ... }``).
25+
See `MongoDB Extended JSON format`_ for a description of Extended JSON formats.
2426

2527
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result.
2628

@@ -36,31 +38,11 @@ Upon failure, NULL is returned.
3638
Example
3739
-------
3840

39-
.. code-block:: c
40-
41-
#include <bson/bson.h>
42-
43-
int main ()
44-
{
45-
bson_t bson;
46-
char *str;
47-
48-
bson_init (&bson);
49-
/* BSON array is a normal BSON document with integer values for the keys,
50-
* starting with 0 and continuing sequentially
51-
*/
52-
BSON_APPEND_DOUBLE (&bson, "0", 3.14);
53-
BSON_APPEND_UTF8 (&bson, "1", "bar");
54-
55-
str = bson_array_as_relaxed_extended_json (&bson, NULL);
56-
/* Prints
57-
* [ 3.14, "bar" ]
58-
*/
59-
printf ("%s\n", str);
60-
bson_free (str);
61-
62-
bson_destroy (&bson);
63-
}
41+
.. literalinclude:: ../examples/extended-json.c
42+
:language: c
43+
:start-after: // bson_array_as_relaxed_extended_json ... begin
44+
:end-before: // bson_array_as_relaxed_extended_json ... end
45+
:dedent: 6
6446

6547

6648
.. only:: html

src/libbson/doc/bson_as_canonical_extended_json.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Parameters
2020
Description
2121
-----------
2222

23-
The :symbol:`bson_as_canonical_extended_json()` encodes ``bson`` as a UTF-8 string in the canonical `MongoDB Extended JSON format`_.
23+
:symbol:`bson_as_canonical_extended_json()` encodes ``bson`` as a UTF-8 string in the Canonical Extended JSON.
24+
See `MongoDB Extended JSON format`_ for a description of Extended JSON formats.
2425

2526
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result.
2627

@@ -36,11 +37,11 @@ Upon failure, NULL is returned.
3637
Example
3738
-------
3839

39-
.. code-block:: c
40-
41-
char *str = bson_as_canonical_extended_json (doc, NULL);
42-
printf ("%s\n", str);
43-
bson_free (str);
40+
.. literalinclude:: ../examples/extended-json.c
41+
:language: c
42+
:start-after: // bson_as_canonical_extended_json ... begin
43+
:end-before: // bson_as_canonical_extended_json ... end
44+
:dedent: 6
4445

4546

4647
.. only:: html

src/libbson/doc/bson_as_json.rst

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
bson_as_json()
44
==============
55

6+
.. warning::
7+
.. deprecated:: 1.29.0
8+
9+
This function is deprecated and should not be used in new code.
10+
611
Synopsis
712
--------
813

914
.. code-block:: c
1015
1116
char *
12-
bson_as_json (const bson_t *bson, size_t *length);
17+
bson_as_json (const bson_t *bson, size_t *length) BSON_GNUC_DEPRECATED_FOR (bson_as_legacy_extended_json);
1318
1419
Parameters
1520
----------
@@ -20,7 +25,9 @@ Parameters
2025
Description
2126
-----------
2227

23-
The :symbol:`bson_as_json()` function shall encode ``bson`` as a UTF-8 string using libbson's legacy JSON format. This function is superseded by :symbol:`bson_as_canonical_extended_json()` and :symbol:`bson_as_relaxed_extended_json()`, which use the same `MongoDB Extended JSON format`_ as all other MongoDB drivers.
28+
:symbol:`bson_as_json()` encodes ``bson`` as a UTF-8 string using :doc:`libbson's Legacy Extended JSON <legacy_extended_json>`.
29+
This function is superseded by :symbol:`bson_as_canonical_extended_json()` and :symbol:`bson_as_relaxed_extended_json()`, which use the same `MongoDB Extended JSON format`_ as all other MongoDB drivers.
30+
To continue producing Legacy Extended JSON, :symbol:`bson_as_legacy_extended_json()` may be used.
2431

2532
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result.
2633

@@ -33,32 +40,6 @@ If successful, a newly allocated UTF-8 encoded string and ``length`` is set.
3340

3441
Upon failure, NULL is returned.
3542

36-
Example
37-
-------
38-
39-
.. code-block:: c
40-
41-
#include <bson/bson.h>
42-
43-
int main ()
44-
{
45-
bson_t bson;
46-
char *str;
47-
48-
bson_init (&bson);
49-
BSON_APPEND_UTF8 (&bson, "0", "foo");
50-
BSON_APPEND_UTF8 (&bson, "1", "bar");
51-
52-
str = bson_as_json (&bson, NULL);
53-
/* Prints
54-
* { "0" : "foo", "1" : "bar" }
55-
*/
56-
printf ("%s\n", str);
57-
bson_free (str);
58-
59-
bson_destroy (&bson);
60-
}
61-
6243
.. only:: html
6344

6445
.. include:: includes/seealso/bson-as-json.txt

0 commit comments

Comments
 (0)