You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-32Lines changed: 32 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ the [JSON standard specification][json-spec] and the extended [JSON 5 specificat
7
7
8
8
This library is shaped around easy analyzation and manipulation of JSON data.
9
9
10
-
- Easy to use JSON tree representation with little as possible `instanceof` checks and casts
11
-
- Quick and easy parsing of files and JSON strings
12
-
- Quick serialization with a high variety of formatting options
13
-
- Reading and writing of streams containing multiple JSON documents (such as over socket streams)
10
+
- Easy to use JSON tree representation with little as possible `instanceof` checks and casts.
11
+
- Quick and easy parsing of files and JSON strings.
12
+
- Quick serialization with a high variety of formatting options.
13
+
- Reading and writing of streams containing multiple JSON documents (such as over socket streams).
14
+
- Intuitive conversion of Java objects from and to JSON trees via codecs, with no use of reflection or annotations (currently experimental).
14
15
- Support for the [JSON 5 specification][json5-spec].
15
16
16
17
## Work in progress
@@ -19,21 +20,21 @@ This library is in development and the API can change at any time, although at t
19
20
20
21
## Installing
21
22
22
-
The current version is `0.7.2`. This version is compatible with Java 11 and above. However, I plan to drop Java 11 compat and move to Java 17 (allowing for sealing the `JsonNode` interface).
23
+
The current version is `0.8`. This version is compatible with Java 17 and above. However, I plan to drop Java 11 compat and move to Java 17 (allowing for sealing the `JsonNode` interface).
23
24
24
-
The artifact can be installed from my [Maven repository](https://maven.runefox.dev/).
25
+
The artifact can be installed from my [Maven repository](https://mvn.runefox.dev/).
-**[All artifacts for v0.8](https://mvn.runefox.dev/#/releases/dev/runefox/json/0.8)**
68
69
69
70
## Usage
70
71
@@ -254,7 +255,7 @@ you don't need to worry about it.
254
255
255
256
### Codecs
256
257
257
-
Codecs are a handy tool to easily encode and decode Java objects into JSON trees and vice versa. All the logic for this can be found in a separate package: `dev.runefox.json.codec`.
258
+
Codecs are a handy tool to easily encode and decode Java objects into JSON trees and vice versa. All the logic for this can be found in a separate package: `dev.runefox.json.codec`. The codec API is still very experimental and may change drastically in further updates.
258
259
259
260
The main type that is important in defining codecs is the `JsonCodec` interface. This interface contains many base codec definitions, for primitives and other basic Java types. You can use codecs of other types to define new codecs.
260
261
@@ -289,7 +290,7 @@ public static final JsonCodec<Person> CODEC
This system is useful for classes with up to 16 serialized fields. Note that a this codec always produces and requires a JSON object. It cannot handle arrays or primitives. See the static methods of `JsonCodec` for other ways to construct codecs.
@@ -335,13 +336,14 @@ requires dev.runefox.json;
335
336
```
336
337
337
338
### Kotlin
339
+
Kotlin support is added through a separate artifact. It's named `jsonkt` and follows the same version as the main artifact.
340
+
```kotlin
341
+
implementation("dev.runefox:jsonkt:<version>")
342
+
```
338
343
339
-
Since 0.7.2 the Kotlin part is a separate artifact and must be added. It's named `jsonkt` and follows
340
-
the same version as the main artifact.
341
-
342
-
Since 0.6.1, the library now integrates better with Kotlin:
344
+
The Kotlin support library adds several Kotlin-style wrappers for the JSON API provided by the main artifact.
Some extra `JsonNode` factory methods were added to reduce the need of escaping reserved kotlin words in backticks. For
355
-
example, `JsonNode.object()` would be called in kotlin as <code>JsonNode.\`object\`()</code>. This is ugly, and since 0.6.1, the `jsonObject()` function is available as a replacement to this. Additional functions like this are added for other types, to keep consistency.
357
+
example, `JsonNode.object()` would be called in kotlin as <code>JsonNode.\`object\`()</code>. This is ugly, and the `JsonObject()` function is available as a replacement to this. Additional functions like this are added for other types, to keep consistency.
356
358
357
-
When using `JsonCodec`s, any object now has the `encoded` infix function, and `JsonNode` also has the reversed `decoded` infix function, allowing for the following syntax:
359
+
When using `JsonCodec`s, any object now has the `encode` infix function, and `JsonNode` also has the reversed `decode` infix function, allowing for the following syntax:
358
360
```kotlin
359
-
val json =LocalDateTime.now() encoded JsonCodec.LOCAL_DATE_TIME
361
+
// Note how JsonCodecs provides codec instances with Kotlin type guarantees.
362
+
val json =LocalDateTime.now() encode JsonCodecs.LOCAL_DATE_TIME
360
363
361
-
println(json decoded JsonCodec.LOCAL_DATE_TIME)
364
+
println(json decode JsonCodecs.LOCAL_DATE_TIME)
362
365
```
363
366
364
367
Since `JsonNode` has natural `get` and `set` methods, Kotlin allows you to call these using subscript notation:
@@ -373,21 +376,18 @@ obj["foo"] = "bar" // also automatically converted to JsonNode
373
376
As an extra feature, elements can be added to an array node using `+=`:
374
377
375
378
```kotlin
376
-
val arr =jsonArray()
379
+
val arr =JsonArray()
377
380
arr +=1
378
381
arr +=2
379
-
arr +=jsonObject()
382
+
arr +=JsonObject()
380
383
381
384
println(arr) // [1, 2, {}]
382
385
```
383
386
384
387
385
388
## Documentation
386
389
387
-
Documentation is being worked on. The most commonly needed parts of the library are well documented with JavaDoc comments. More documentation coming
388
-
in later versions.
389
-
390
-
I am working on hosting the compiled JavaDoc online.
390
+
Documentation is provided as JavaDoc (and KDoc) comments in the source code. The most commonly needed parts of the library are well documented with JavaDoc comments. More documentation coming as I work on the project.
391
391
392
392
## Changelog
393
393
@@ -399,7 +399,7 @@ Since 0.7.2, changelogs have moved to GitHub Releases. See [Release v0.7.2](http
399
399
400
400
Copyright 2022-2025 O. W. Nankman
401
401
402
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
402
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the
0 commit comments