@@ -39,15 +39,34 @@ An annotation processor converting JSON schemas to java records.
39393 . Add your JSON schema files to the class path:
4040 ```
4141 src/main/resources/com/aqme
42- └── foo.schema.json
42+ └── customer.json
43+ ```
44+ ``` json
45+ {
46+ "$schema" : " https://json-schema.org/draft/2020-12/schema" ,
47+ "$id" : " customer" ,
48+ "type" : " object" ,
49+ "properties" : {
50+ "firstName" : {
51+ "type" : " string"
52+ },
53+ "lastName" : {
54+ "type" : " string"
55+ }
56+ },
57+ "required" : [
58+ " firstName" ,
59+ " lastName"
60+ ]
61+ }
4362 ```
44634 . Annotate a ` package-info.java ` file like this:
4564 ``` java
4665 @GenerateRecordsFromJsonSchemas (
4766 schemaRootFileLocations =
4867 @JsonSchemaFileLocation (
4968 moduleAndPackage = " com.aqme" ,
50- relativeName = " foo.schema .json"
69+ relativeName = " customer .json"
5170 )
5271 )
5372 package com.aqme ;
@@ -56,7 +75,28 @@ An annotation processor converting JSON schemas to java records.
5675 import com.cosium.json_schema_to_java_record_api.JsonSchemaConfiguration ;
5776 import com.cosium.json_schema_to_java_record_api.JsonSchemaFileLocation ;
5877 ```
59- 5 . Compile to generate the java files
78+ 5 . Compile to generate this kind of output:
79+ ``` java
80+ package com.aqme ;
81+
82+ import com.fasterxml.jackson.annotation.JsonInclude ;
83+ import com.fasterxml.jackson.annotation.JsonProperty ;
84+ import java.util.Objects ;
85+ import javax.annotation.processing.Generated ;
86+ import org.jspecify.annotations.NonNull ;
87+ import org.jspecify.annotations.Nullable ;
88+
89+ @JsonInclude (JsonInclude . Include . NON_NULL )
90+ @Generated (" com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas" )
91+ public record Customer(
92+ @JsonProperty (" firstName" ) @NonNull String firstName,
93+ @JsonProperty (" lastName" ) @NonNull String lastName) {
94+ public Customer {
95+ Objects . requireNonNull(firstName);
96+ Objects . requireNonNull(lastName);
97+ }
98+ }
99+ ```
60100
61101# Type mapping
62102
@@ -81,7 +121,7 @@ A schema having a non-null `enum` array will be converted to a java enum.
81121
82122# Java JSON binding
83123
84- Record components will be annotated with [ Jackson annotations] ( https://github.com/FasterXML/jackson-annotations )
124+ Record components will be annotated with [ Jackson annotations] ( https://github.com/FasterXML/jackson-annotations ) .
85125
86126# Nullability
87127
0 commit comments