Skip to content

Commit ea458b2

Browse files
docs: document JsonValue construction in readme (#528)
1 parent 70240ef commit ea458b2

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

README.md

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

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

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

403403
```java
404404
import com.lithic.api.core.JsonValue;
@@ -409,6 +409,45 @@ CardCreateParams params = CardCreateParams.builder()
409409
.build();
410410
```
411411

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

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

0 commit comments

Comments
 (0)