|
1 |
| -# json-schema-to-java-record |
| 1 | +[](https://github.com/Cosium/json-schema-to-java-record/actions/workflows/ci.yml) |
| 2 | +[](https://central.sonatype.com/artifact/com.cosium.json_schema_to_java_record/json-schema-to-java-record) |
| 3 | + |
| 4 | +# JSON Schema To Java Record |
| 5 | + |
| 6 | +An annotation processor converting JSON schemas to java records. |
| 7 | + |
| 8 | +# Quick start |
| 9 | + |
| 10 | +1. Import the BOM: |
| 11 | + ```xml |
| 12 | + <dependencyManagement> |
| 13 | + <dependencies> |
| 14 | + <!-- ... --> |
| 15 | + <dependency> |
| 16 | + <groupId>com.cosium.json_schema_to_java_record</groupId> |
| 17 | + <artifactId>json-schema-to-java-record-bom</artifactId> |
| 18 | + <version>${json-schema-to-java-record.version}</version> |
| 19 | + <scope>import</scope> |
| 20 | + <type>pom</type> |
| 21 | + </dependency> |
| 22 | + <!-- ... --> |
| 23 | + </dependencies> |
| 24 | + </dependencyManagement> |
| 25 | + ``` |
| 26 | +2. Import the API: |
| 27 | + ```xml |
| 28 | + <dependencies> |
| 29 | + <!-- ... --> |
| 30 | + <dependency> |
| 31 | + <groupId>com.cosium.json_schema_to_java_record</groupId> |
| 32 | + <artifactId>json-schema-to-java-record-api</artifactId> |
| 33 | + </dependency> |
| 34 | + <!-- ... --> |
| 35 | + </dependencies> |
| 36 | + ``` |
| 37 | +3. Import the annotation processor: |
| 38 | + ```xml |
| 39 | + <plugin> |
| 40 | + <groupId>org.apache.maven.plugins</groupId> |
| 41 | + <artifactId>maven-compiler-plugin</artifactId> |
| 42 | + <configuration> |
| 43 | + <annotationProcessorPaths> |
| 44 | + <path> |
| 45 | + <groupId>com.cosium.json_schema_to_java_record</groupId> |
| 46 | + <artifactId>json-schema-to-java-record</artifactId> |
| 47 | + </path> |
| 48 | + </annotationProcessorPaths> |
| 49 | + </configuration> |
| 50 | + </plugin> |
| 51 | + ``` |
| 52 | +4. Add your JSON schema files to the class path: |
| 53 | + ``` |
| 54 | + src/main/resources/com/aqme |
| 55 | + └── foo.schema.json |
| 56 | + ``` |
| 57 | +5. Annotate a `package-info.java` file like this: |
| 58 | + ```java |
| 59 | + @GenerateRecordsFromJsonSchemas( |
| 60 | + schemaRootFileLocations = |
| 61 | + @JsonSchemaFileLocation( |
| 62 | + moduleAndPackage = "com.aqme", |
| 63 | + relativeName = "foo.schema.json" |
| 64 | + ) |
| 65 | + ) |
| 66 | + package com.aqme; |
| 67 | + |
| 68 | + import com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas; |
| 69 | + import com.cosium.json_schema_to_java_record_api.JsonSchemaConfiguration; |
| 70 | + import com.cosium.json_schema_to_java_record_api.JsonSchemaFileLocation; |
| 71 | + ``` |
| 72 | +6. Compile to generate the java files |
0 commit comments