use of org.jsonschema2pojo.SchemaMapper in project jsonschema2pojo by joelittlejohn.
the class Example method main.
public static void main(String[] args) throws IOException {
// BEGIN EXAMPLE
JCodeModel codeModel = new JCodeModel();
URL source = Example.class.getResource("/schema/required.json");
GenerationConfig config = new DefaultGenerationConfig() {
@Override
public boolean isGenerateBuilders() {
// set config option by overriding method
return true;
}
};
SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());
mapper.generate(codeModel, "ClassName", "com.example", source);
codeModel.build(Files.createTempDirectory("required").toFile());
// END EXAMPLE
}
use of org.jsonschema2pojo.SchemaMapper in project jsonschema2pojo by joelittlejohn.
the class SelfRefIT method nestedSelfRefsInStringContentWithoutParentFile.
@Test
public void nestedSelfRefsInStringContentWithoutParentFile() throws NoSuchMethodException, ClassNotFoundException, IOException {
String schemaContents = IOUtils.toString(CodeGenerationHelper.class.getResource("/schema/ref/nestedSelfRefsReadAsString.json"));
JCodeModel codeModel = new JCodeModel();
new SchemaMapper().generate(codeModel, "NestedSelfRefsInString", "com.example", schemaContents);
codeModel.build(schemaRule.getGenerateDir());
ClassLoader classLoader = schemaRule.compile();
Class<?> nestedSelfRefs = classLoader.loadClass("com.example.NestedSelfRefsInString");
assertThat(nestedSelfRefs.getMethod("getThings").getReturnType().getSimpleName(), equalTo("List"));
Class<?> listEntryType = (Class<?>) ((ParameterizedType) nestedSelfRefs.getMethod("getThings").getGenericReturnType()).getActualTypeArguments()[0];
assertThat(listEntryType.getName(), equalTo("com.example.Thing"));
Class<?> thingClass = classLoader.loadClass("com.example.Thing");
assertThat(thingClass.getMethod("getNamespace").getReturnType().getSimpleName(), equalTo("String"));
assertThat(thingClass.getMethod("getName").getReturnType().getSimpleName(), equalTo("String"));
assertThat(thingClass.getMethod("getVersion").getReturnType().getSimpleName(), equalTo("String"));
}
Aggregations