Skip to content

Commit 9401e34

Browse files
docs: document JsonValue construction in readme (#330)
1 parent 9a2a812 commit 9401e34

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ CustomerCreateParams params = CustomerCreateParams.builder()
402402

403403
These properties can be accessed on the nested built object later using the `_additionalProperties()` method.
404404

405-
To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](orb-java-core/src/main/kotlin/com/withorb/api/core/JsonValue.kt) object to its setter:
405+
To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](orb-java-core/src/main/kotlin/com/withorb/api/core/Values.kt) object to its setter:
406406

407407
```java
408408
import com.withorb.api.core.JsonValue;
@@ -414,6 +414,45 @@ CustomerCreateParams params = CustomerCreateParams.builder()
414414
.build();
415415
```
416416

417+
The most straightforward way to create a [`JsonValue`](orb-java-core/src/main/kotlin/com/withorb/api/core/Values.kt) is using its `from(...)` method:
418+
419+
```java
420+
import com.withorb.api.core.JsonValue;
421+
import java.util.List;
422+
import java.util.Map;
423+
424+
// Create primitive JSON values
425+
JsonValue nullValue = JsonValue.from(null);
426+
JsonValue booleanValue = JsonValue.from(true);
427+
JsonValue numberValue = JsonValue.from(42);
428+
JsonValue stringValue = JsonValue.from("Hello World!");
429+
430+
// Create a JSON array value equivalent to `["Hello", "World"]`
431+
JsonValue arrayValue = JsonValue.from(List.of(
432+
"Hello", "World"
433+
));
434+
435+
// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
436+
JsonValue objectValue = JsonValue.from(Map.of(
437+
"a", 1,
438+
"b", 2
439+
));
440+
441+
// Create an arbitrarily nested JSON equivalent to:
442+
// {
443+
// "a": [1, 2],
444+
// "b": [3, 4]
445+
// }
446+
JsonValue complexValue = JsonValue.from(Map.of(
447+
"a", List.of(
448+
1, 2
449+
),
450+
"b", List.of(
451+
3, 4
452+
)
453+
));
454+
```
455+
417456
### Response properties
418457

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

0 commit comments

Comments
 (0)