Skip to content

Commit d512c8d

Browse files
committed
doc: update readme
1 parent 34fa953 commit d512c8d

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

README.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# JSON Schema Compiler
22

3-
> ⚠️ WARNING! WORK IN PROGRESS: This project is in an early stage and should not be considered production-ready. Use it at your
3+
> ⚠️ WARNING! WORK IN PROGRESS: This project is in an early stage and should not be considered production-ready. Use it
4+
> at your
45
> own risk.
56
6-
When you need to integrate JSON-Schema models into JVM-based applications, you can use several tools to translate it
7-
Java, or other supported language, and then compile it along with your application.
7+
`json-schema-compiler`, **compiles JSON-Schema code directly to bytecode**, in both in `.class` files and `.jar`
8+
libraries, eliminating the need to translate the schema to other programming language and then compiling it.
89

9-
This approach works for many use cases, but requires a complete development kit and takes an indirect path as you need
10-
translate one language to another, and then use a compiler to create your executable.
10+
This makes the process faster, removes the need of a development kit available, and reduces the complexity to
11+
integrate such schemas into JVM-based applications.
1112

12-
`json-schema-compiler`, as it's name implies, **compiles JSON-Schema code directly to bytecode**. This removes the need
13-
to have a development kit available, and reduces the complexity to integrate such schemas into JVM-based applications.
14-
15-
## How to use
13+
## How to compile JSON Schema files to bytecode
1614

1715
`json-schema-compiler` is a command line utility. The general syntax is:
1816

@@ -22,12 +20,12 @@ json-schema-compiler -p [package] -o [output]
2220

2321
Supported parameters:
2422

25-
| parameter | default value | description |
26-
|-------------------------|---------------|------------------------------------------------|
27-
| `-p` , `--package-name` | empty | The package where generated classes should be. |
28-
| `-o` , `--output` | "." | The output folder for the generated classes. |
23+
| parameter | default value | description |
24+
|-------------------------|---------------|---------------------------------------------------------------------------------------|
25+
| `-p` , `--package-name` | empty | The package where generated classes should be. |
26+
| `-o` , `--output` | "." | The output folder for the generated classes, or the path of the jar file to generate. |
2927

30-
### 1. Download your specific image
28+
### 1. Download your specific image, or generate one
3129

3230
Everytime the code is updated a new native image is generated for Windows, Linux and MacOS
3331
using [GraalVM's Native Image](https://www.graalvm.org/latest/reference-manual/native-image/). You can find the image
@@ -40,17 +38,37 @@ for your operating system under the `[OS]-current` tag:
4038
Once downloaded, you can run it directly from your current folder, or add it to your systems `$PATH` so that it can be
4139
launched from anywhere.
4240

41+
If your system is not listed here, you can generate your own image by:
42+
43+
1. Installing the [GraalVM JDK](https://www.graalvm.org/downloads/)
44+
2. Cloning this repository a
45+
3. Running the [create_image.sh](./create-image.sh) script
46+
47+
The script will build and image for your current operating system and architecture, and put it in the `bin/local`
48+
folder.
49+
4350
### 2. Compile json schema files
4451

4552
If you are using `json-schema-compiler` in a UNIX-like environment, you can pass the JSON code trough standard input:
4653

4754
```bash
55+
# compile as .class files in the ./output folder:
4856
cat /my/json-schema/file.json | json-schema-compiler -p com.example -o ./output
4957
```
5058

59+
```bash
60+
# compile as ./library.jar:
61+
cat /my/json-schema/file.json | json-schema-compiler -p com.example -o ./library.jar
62+
```
63+
5164
You can also pass the json schema's path as an argument:
5265

5366
```bash
54-
json-schema-compiler -p com.example -o ./output /my/json-schema/file.json
67+
json-schema-compiler -p com.example -o ./library.jar /my/json-schema/file.json
5568
```
5669

70+
## How it works
71+
72+
This compiler makes heavy use of the [Java Class-File API](https://openjdk.org/jeps/484) to generate bytecode directly
73+
at runtime. You have more details about this project
74+
in [this article I wrote](https://www.nachobrito.es/sideprojects/json-schema-compiler/).

nested.jar

2.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)