@@ -39,15 +39,34 @@ An annotation processor converting JSON schemas to java records.
39
39
3 . Add your JSON schema files to the class path:
40
40
```
41
41
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
+ }
43
62
```
44
63
4 . Annotate a ` package-info.java ` file like this:
45
64
``` java
46
65
@GenerateRecordsFromJsonSchemas (
47
66
schemaRootFileLocations =
48
67
@JsonSchemaFileLocation (
49
68
moduleAndPackage = " com.aqme" ,
50
- relativeName = " foo.schema .json"
69
+ relativeName = " customer .json"
51
70
)
52
71
)
53
72
package com.aqme ;
@@ -56,7 +75,28 @@ An annotation processor converting JSON schemas to java records.
56
75
import com.cosium.json_schema_to_java_record_api.JsonSchemaConfiguration ;
57
76
import com.cosium.json_schema_to_java_record_api.JsonSchemaFileLocation ;
58
77
```
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
+ ```
60
100
61
101
# Type mapping
62
102
@@ -81,7 +121,7 @@ A schema having a non-null `enum` array will be converted to a java enum.
81
121
82
122
# Java JSON binding
83
123
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 ) .
85
125
86
126
# Nullability
87
127
0 commit comments