-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
150 lines (137 loc) · 5.25 KB
/
index.html
File metadata and controls
150 lines (137 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>java.util.json Backport for JDK 21+</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
color: #333;
max-width: 900px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background-color: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1, h2, h3 {
color: #2c3e50;
}
h1 {
border-bottom: 3px solid #3498db;
padding-bottom: 10px;
}
pre {
background-color: #f4f4f4;
border: 1px solid #ddd;
border-radius: 4px;
padding: 15px;
overflow-x: auto;
}
code {
background-color: #f4f4f4;
padding: 2px 4px;
border-radius: 3px;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}
.highlight {
background-color: #fff3cd;
border-left: 4px solid #ffc107;
padding: 10px;
margin: 15px 0;
}
.button {
display: inline-block;
padding: 10px 20px;
background-color: #3498db;
color: white;
text-decoration: none;
border-radius: 5px;
margin-right: 10px;
margin-top: 10px;
}
.button:hover {
background-color: #2980b9;
}
.button.secondary {
background-color: #95a5a6;
}
.button.secondary:hover {
background-color: #7f8c8d;
}
</style>
</head>
<body>
<div class="container">
<h1>java.util.json Backport for JDK 21+</h1>
<div class="highlight">
<strong>Early Access:</strong> This is an unofficial backport of the experimental <code>java.util.json</code> API from OpenJDK sandbox,
enabling developers to use future JSON API patterns today on JDK 21+.
</div>
<h2>Quick Start</h2>
<h3>Maven Dependency</h3>
<pre><code>
<dependency>
<groupId>io.github.simbo1905.json</groupId>
<artifactId>java.util.json</artifactId>
<version>0.1.8</version>
</dependency>
</code></pre>
<h3>Simple Example</h3>
<pre><code>import jdk.sandbox.java.util.json.*;
// Parse JSON
JsonValue value = Json.parse("{\"name\":\"Alice\",\"age\":30}");
JsonObject obj = (JsonObject) value;
// Access values
String name = ((JsonString) obj.members().get("name")).string();
int age = Math.toIntExact(((JsonNumber) obj.members().get("age")).toLong());</code></pre>
<h2>Key Features</h2>
<ul>
<li><strong>Future-Compatible API:</strong> Write code today that will work with tomorrow's official <code>java.util.json</code></li>
<li><strong>Sealed Type Hierarchy:</strong> Type-safe JSON values using Java's sealed classes</li>
<li><strong>Record Integration:</strong> Seamless mapping between Java records and JSON</li>
<li><strong>Pattern Matching:</strong> Leverage modern Java features for elegant JSON handling</li>
<li><strong>Immutable Values:</strong> Thread-safe by design</li>
</ul>
<h2>Record Mapping Example</h2>
<pre><code>// Domain model
record User(String name, String email, boolean active) {}
record Team(String teamName, List<User> members) {}
// Convert to JSON
Team team = new Team("Engineering", List.of(
new User("Alice", "alice@example.com", true),
new User("Bob", "bob@example.com", false)
));
JsonValue teamJson = JsonObject.of(Map.of(
"teamName", JsonString.of(team.teamName()),
"members", JsonArray.of(team.members().stream()
.map(u -> JsonObject.of(Map.of(
"name", JsonString.of(u.name()),
"email", JsonString.of(u.email()),
"active", JsonBoolean.of(u.active())
)))
.toList())
));</code></pre>
<h2>Resources</h2>
<a href="https://github.com/simbo1905/java.util.json.Java21" class="button">View on GitHub</a>
<a href="Towards%20a%20JSON%20API%20for%20the%20JDK.pdf" class="button secondary">Original Proposal</a>
<a href="https://github.com/openjdk/jdk-sandbox/tree/json" class="button secondary">OpenJDK Sandbox</a>
<h2>Status</h2>
<p>
This code (as of 2025-09-04) is derived from the OpenJDK jdk-sandbox repository “json”
branch at commit
<a href="https://github.com/openjdk/jdk-sandbox/commit/a8e7de8b49e4e4178eb53c94ead2fa2846c30635">Produce path/col during path building</a>.
The API may evolve as the official specification develops.
</p>
<h2>License</h2>
<p>Licensed under the GNU General Public License version 2 with Classpath exception,
same as the OpenJDK project.</p>
</div>
</body>
</html>