Skip to content

Commit 33b937d

Browse files
committed
Document type conversion utilities (fromUntyped/toUntyped)
Added comprehensive documentation for the Json.fromUntyped() and Json.toUntyped() methods that provide bidirectional conversion between JsonValue objects and standard Java collections/types. Includes usage examples and type mappings.
1 parent 558d5bf commit 33b937d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,40 @@ The API provides immutable JSON value types:
4343
Parsing is done via the `Json` class:
4444
```java
4545
JsonValue value = Json.parse(jsonString);
46-
```
46+
```
47+
48+
## Type Conversion Utilities
49+
50+
The `Json` class provides bidirectional conversion between `JsonValue` objects and standard Java types:
51+
52+
### Converting from Java Objects to JSON (`fromUntyped`)
53+
```java
54+
// Convert standard Java collections to JsonValue
55+
Map<String, Object> data = Map.of(
56+
"name", "John",
57+
"age", 30,
58+
"scores", List.of(85, 92, 78)
59+
);
60+
JsonValue json = Json.fromUntyped(data);
61+
```
62+
63+
### Converting from JSON to Java Objects (`toUntyped`)
64+
```java
65+
// Convert JsonValue back to standard Java types
66+
JsonValue parsed = Json.parse("{\"name\":\"John\",\"age\":30}");
67+
Object data = Json.toUntyped(parsed);
68+
// Returns a Map<String, Object> with standard Java types
69+
```
70+
71+
The conversion mappings are:
72+
- `JsonObject``Map<String, Object>`
73+
- `JsonArray``List<Object>`
74+
- `JsonString``String`
75+
- `JsonNumber``Number` (Long, Double, BigInteger, or BigDecimal)
76+
- `JsonBoolean``Boolean`
77+
- `JsonNull``null`
78+
79+
This is useful for:
80+
- Integrating with existing code that uses standard collections
81+
- Serializing/deserializing to formats that expect Java types
82+
- Working with frameworks that use reflection on standard types
File renamed without changes.

0 commit comments

Comments
 (0)