Skip to content

Commit ed6227f

Browse files
committed
edits
1 parent 31cfbeb commit ed6227f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

source/data-formats/extended-json.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ JSON:
121121
.. output::
122122
:visible: false
123123

124-
{"_id": {"$oid": "507f1f77bcf86cd799439012"}, "myNumber": 11223344}
124+
{"_id": {"$oid": "507f1f77bcf86cd799439012"}, "createdAt": {"$date": "2020-09-30T21:00:09Z"}, "myNumber": 4794261}
125125

126126
.. _kotlin-sync-write-ejson-jsonwriter:
127127

128128
Use the JsonWriter Class
129129
~~~~~~~~~~~~~~~~~~~~~~~~
130130

131-
To output an Extended JSON string from data stored in {+language+} objects, use
131+
To output an Extended JSON string from data stored in {+language+} objects, you can use
132132
the BSON library's ``JsonWriter`` class. To construct a ``JsonWriter`` object,
133133
pass a subclass of a Java ``Writer`` to specify how you want to output the Extended
134134
JSON. Optionally, you can pass a ``JsonWriterSettings`` instance to specify options,
@@ -161,7 +161,8 @@ can further customize the output by adding converters to your
161161
``JsonWriterSettings`` object. These converter methods specify logic
162162
for handling different data types during the conversion process.
163163

164-
The following example defines the ``objectIdConverter()`` and ``dateTimeConverter()``
164+
The following example converts the same document as the :ref:`kotlin-sync-write-ejson-doc`
165+
example. However, this example defines the ``objectIdConverter()`` and ``dateTimeConverter()``
165166
converter methods in a ``JsonWriterSettings`` object to simplify the Relaxed mode
166167
Extended JSON output:
167168

source/includes/data-formats/ext-json.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ fun main() {
3636
""".trimIndent()
3737

3838
val jsonReader = JsonReader(string)
39-
4039
jsonReader.readStartDocument()
4140

41+
// Reads the "_id" field value
4242
jsonReader.readName("_id")
4343
val id = jsonReader.readObjectId()
4444

45+
// Reads the "myNumber" field value
4546
jsonReader.readName("myNumber")
4647
val myNumber = jsonReader.readInt64()
4748

@@ -54,9 +55,10 @@ fun main() {
5455
// end-read-bson
5556

5657
// start-write-doc
57-
val myDoc = Document()
58+
val doc = Document()
5859
.append("_id", ObjectId("507f1f77bcf86cd799439012"))
59-
.append("myNumber", 11223344)
60+
.append("createdAt", Date.from(Instant.ofEpochMilli(1601499609000L)))
61+
.append("myNumber", 4794261)
6062

6163
val settings = JsonWriterSettings.builder()
6264
.outputMode(JsonMode.RELAXED)
@@ -82,7 +84,7 @@ fun main() {
8284
// end-write-bson
8385

8486
// start-custom-conversion
85-
val settings = JsonWriterSettings.builder()
87+
val settings = JsonWriterSettings.builder()
8688
.outputMode(JsonMode.RELAXED)
8789
.objectIdConverter { value, writer ->
8890
writer.writeString(value.toHexString())

0 commit comments

Comments
 (0)