Skip to content

Commit 84a8ff4

Browse files
docs: document JsonValue construction in readme (#123)
1 parent 40cf55b commit 84a8ff4

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
@@ -323,14 +323,53 @@ ProductListParams params = ProductListParams.builder()
323323

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

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

328328
```java
329329
import shop.terminal.api.models.ProductListParams;
330330

331331
ProductListParams params = ProductListParams.builder().build();
332332
```
333333

334+
The most straightforward way to create a [`JsonValue`](terminal-java-core/src/main/kotlin/shop/terminal/api/core/Values.kt) is using its `from(...)` method:
335+
336+
```java
337+
import java.util.List;
338+
import java.util.Map;
339+
import shop.terminal.api.core.JsonValue;
340+
341+
// Create primitive JSON values
342+
JsonValue nullValue = JsonValue.from(null);
343+
JsonValue booleanValue = JsonValue.from(true);
344+
JsonValue numberValue = JsonValue.from(42);
345+
JsonValue stringValue = JsonValue.from("Hello World!");
346+
347+
// Create a JSON array value equivalent to `["Hello", "World"]`
348+
JsonValue arrayValue = JsonValue.from(List.of(
349+
"Hello", "World"
350+
));
351+
352+
// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
353+
JsonValue objectValue = JsonValue.from(Map.of(
354+
"a", 1,
355+
"b", 2
356+
));
357+
358+
// Create an arbitrarily nested JSON equivalent to:
359+
// {
360+
// "a": [1, 2],
361+
// "b": [3, 4]
362+
// }
363+
JsonValue complexValue = JsonValue.from(Map.of(
364+
"a", List.of(
365+
1, 2
366+
),
367+
"b", List.of(
368+
3, 4
369+
)
370+
));
371+
```
372+
334373
### Response properties
335374

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

0 commit comments

Comments
 (0)