@@ -122,4 +122,136 @@ All `$ref` values should start with `classpath:`, followed by the absolute path
122122 }
123123 }
124124}
125+ ```
126+
127+ # Customization
128+
129+ Most customizations rely on the JSON schema ` $id ` attribute (aka ` schemaId ` on the java API side).
130+ Make sure this attribute is valued and unique to benefit from customizations using it.
131+
132+ ## Forcing the Java type qualified name of a particular schema
133+
134+ You can ask a particular ` schemaId `
135+ to be bound to an explicit Java type qualified name via ` JsonSchemaConfiguration#javaTypeQualifiedName ` .
136+
137+ Example of JSON schema ` country.json ` :
138+ ``` json
139+ {
140+ "$schema" : " https://json-schema.org/draft/2020-12/schema" ,
141+ "$id" : " country" ,
142+ "enum" : [" FRANCE" , " MOROCCO" ]
143+ }
144+ ```
145+
146+ Example of configuration:
147+ ``` java
148+ @GenerateRecordsFromJsonSchemas (
149+ schemaRootFileLocations =
150+ @JsonSchemaFileLocation (
151+ moduleAndPackage = " com.cosium.json_schema_to_java_record_tests.case1" ,
152+ relativeName = " country.json" ),
153+ schemaConfigurations =
154+ @JsonSchemaConfiguration (
155+ schemaId = " country" ,
156+ javaTypeQualifiedName = " com.cosium.json_schema_to_java_record_tests.case1.Country" )
157+ )
158+ package com.cosium.json_schema_to_java_record_tests.case1 ;
159+ ```
160+
161+ Example of generated java class:
162+ ``` java
163+ package com.cosium.json_schema_to_java_record_tests.case1 ;
164+
165+ import javax.annotation.processing.Generated ;
166+
167+ @Generated (" com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas" )
168+ public enum Country {
169+ MOROCCO ,
170+ FRANCE
171+ }
172+ ```
173+
174+ ## Making a generated type implement interfaces
175+
176+ You can ask a generated Java type
177+ to implement a list of interfaces via ` JsonSchemaConfiguration#javaInterfaceQualifiedNames ` .
178+
179+ Example of JSON schema ` country.json ` :
180+ ``` json
181+ {
182+ "$schema" : " https://json-schema.org/draft/2020-12/schema" ,
183+ "$id" : " country" ,
184+ "enum" : [" FRANCE" , " MOROCCO" ]
185+ }
186+ ```
187+
188+ Example of configuration:
189+ ``` java
190+ @GenerateRecordsFromJsonSchemas (
191+ schemaRootFileLocations =
192+ @JsonSchemaFileLocation (
193+ moduleAndPackage = " com.cosium.json_schema_to_java_record_tests.case1" ,
194+ relativeName = " country.json" ),
195+ schemaConfigurations =
196+ @JsonSchemaConfiguration (
197+ schemaId = " country" ,
198+ javaInterfaceQualifiedNames =
199+ " com.cosium.json_schema_to_java_record_tests.case1.Location" )
200+ )
201+ package com.cosium.json_schema_to_java_record_tests.case1 ;
202+ ```
203+
204+ Example of generated java class:
205+ ``` java
206+ import com.cosium.json_schema_to_java_record_tests.case1.Location ;
207+ import javax.annotation.processing.Generated ;
208+
209+ @Generated (" com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas" )
210+ public enum Country implements Location {
211+ MOROCCO ,
212+ FRANCE
213+ }
214+ ```
215+
216+ ## Report generation
217+
218+ You can ask for the creation of a Java class generation report
219+ by providing a non-empty value to ` GenerateRecordsFromJsonSchemas#reportClassQualifiedName ` .
220+
221+ The generated report class will contain:
222+ - A public constant ` Map<String, Class> CLASS_BY_SCHEMA_ID ` mapping each generated class to its JSON schema ` $id ` . If the latter was missing, there will be no entry in the Map.
223+
224+ Example of configuration:
225+ ``` java
226+ @GenerateRecordsFromJsonSchemas (
227+ schemaRootFileLocations =
228+ @JsonSchemaFileLocation (
229+ moduleAndPackage = " com.cosium.json_schema_to_java_record_tests.case1" ,
230+ relativeName = " customers.json"
231+ ),
232+ reportClassQualifiedName = " com.cosium.json_schema_to_java_record_tests.case1.Report"
233+ )
234+ package com.aqme ;
235+
236+ import com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas ;
237+ import com.cosium.json_schema_to_java_record_api.JsonSchemaFileLocation ;
238+
239+ ```
240+
241+ Example of generated report class:
242+ ``` java
243+ package com.cosium.json_schema_to_java_record_tests.case1 ;
244+
245+ import java.lang.Class ;
246+ import java.lang.String ;
247+ import java.util.Map ;
248+ import javax.annotation.processing.Generated ;
249+
250+ @Generated (" com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas" )
251+ public final class Report {
252+ public static final Map<String , Class > CLASS_BY_SCHEMA_ID = Map . ofEntries(Map . entry(" country" ,Country . class),Map . entry(" address" ,Address . class),Map . entry(" customers" ,Customers . class),Map . entry(" customer" ,Customer . class));
253+
254+ private Report () {
255+ }
256+ }
125257```
0 commit comments