Skip to content

Commit d093175

Browse files
docs: document JsonValue construction in readme (#279)
1 parent 0d9b03e commit d093175

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,49 @@ val params: CurrentTimeRetrieveParams = CurrentTimeRetrieveParams.builder()
307307

308308
These can be accessed on the built object later using the `_additionalHeaders()`, `_additionalQueryParams()`, and `_additionalBodyProperties()` methods.
309309

310-
To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/core/JsonValue.kt) object to its setter:
310+
To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/core/Values.kt) object to its setter:
311311

312312
```kotlin
313313
import org.onebusaway.models.CurrentTimeRetrieveParams
314314

315315
val params: CurrentTimeRetrieveParams = CurrentTimeRetrieveParams.builder().build()
316316
```
317317

318+
The most straightforward way to create a [`JsonValue`](onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/core/Values.kt) is using its `from(...)` method:
319+
320+
```kotlin
321+
import org.onebusaway.core.JsonValue
322+
323+
// Create primitive JSON values
324+
val nullValue: JsonValue = JsonValue.from(null)
325+
val booleanValue: JsonValue = JsonValue.from(true)
326+
val numberValue: JsonValue = JsonValue.from(42)
327+
val stringValue: JsonValue = JsonValue.from("Hello World!")
328+
329+
// Create a JSON array value equivalent to `["Hello", "World"]`
330+
val arrayValue: JsonValue = JsonValue.from(listOf(
331+
"Hello", "World"
332+
))
333+
334+
// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
335+
val objectValue: JsonValue = JsonValue.from(mapOf(
336+
"a" to 1, "b" to 2
337+
))
338+
339+
// Create an arbitrarily nested JSON equivalent to:
340+
// {
341+
// "a": [1, 2],
342+
// "b": [3, 4]
343+
// }
344+
val complexValue: JsonValue = JsonValue.from(mapOf(
345+
"a" to listOf(
346+
1, 2
347+
), "b" to listOf(
348+
3, 4
349+
)
350+
))
351+
```
352+
318353
### Response properties
319354

320355
To access undocumented response properties, call the `_additionalProperties()` method:

0 commit comments

Comments
 (0)