本文整理汇总了Java中org.jsonschema2pojo.rules.RuleFactory类的典型用法代码示例。如果您正苦于以下问题:Java RuleFactory类的具体用法?Java RuleFactory怎么用?Java RuleFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuleFactory类属于org.jsonschema2pojo.rules包,在下文中一共展示了RuleFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCustomRuleFactory
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Class<? extends RuleFactory> getCustomRuleFactory() {
if (isNotBlank(customRuleFactory)) {
try {
return (Class<? extends RuleFactory>) Class.forName(customRuleFactory);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} else {
return RuleFactory.class;
}
}
示例2: setCustomRuleFactory
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void setCustomRuleFactory(String customRuleFactory) {
if (isNotBlank(customRuleFactory)) {
try {
this.customRuleFactory = (Class<? extends RuleFactory>) Class.forName(customRuleFactory);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} else {
this.customRuleFactory = RuleFactory.class;
}
}
示例3: selfRefWithoutParentFile
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Test
public void selfRefWithoutParentFile() throws IOException {
JCodeModel codeModel = new JCodeModel();
JsonNode schema = new ObjectMapper().readTree("{\"type\":\"object\", \"properties\":{\"a\":{\"$ref\":\"#/b\"}}, \"b\":\"string\"}");
JPackage p = codeModel._package("com.example");
new RuleFactory().getSchemaRule().apply("Example", schema, p, new Schema(null, schema, schema));
}
示例4: refToInnerFragmentThatHasRefToOuterFragmentWithoutParentFile
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Test
public void refToInnerFragmentThatHasRefToOuterFragmentWithoutParentFile() throws IOException, ClassNotFoundException {
JCodeModel codeModel = new JCodeModel();
JsonNode schema = new ObjectMapper().readTree("{\n" +
" \"type\": \"object\",\n" +
" \"definitions\": {\n" +
" \"location\": {\n" +
" \"type\": \"object\",\n" +
" \"properties\": {\n" +
" \"cat\": {\n" +
" \"$ref\": \"#/definitions/cat\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"cat\": {\n" +
" \"type\": \"number\"\n" +
" }\n" +
" },\n" +
" \"properties\": {\n" +
" \"location\": {\n" +
" \"$ref\": \"#/definitions/location\"\n" +
" }\n" +
" }\n" +
"}");
JPackage p = codeModel._package("com.example");
new RuleFactory().getSchemaRule().apply("Example", schema, p, new Schema(null, schema, schema));
}
示例5: createSchemaMapper
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
private SchemaMapper createSchemaMapper() {
final RuleFactory ruleFactory = new RuleFactory();
ruleFactory.setAnnotator(new Jackson2Annotator() {
@Override
public boolean isAdditionalPropertiesSupported() {
return false;
}
});
ruleFactory.setGenerationConfig(config);
return new SchemaMapper(ruleFactory, new SchemaGenerator());
}
示例6: getCustomRuleFactory
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Override
public Class<? extends RuleFactory> getCustomRuleFactory() {
return RuleFactory.class;
}
示例7: main
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
// BEGIN EXAMPLE
JCodeModel codeModel = new JCodeModel();
URL source = new URL("file:///path/to/my/schema.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(new File("output"));
// END EXAMPLE
}
示例8: generateReadsSchemaAsObject
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Test
public void generateReadsSchemaAsObject() throws IOException {
final SchemaRule mockSchemaRule = mock(SchemaRule.class);
final RuleFactory mockRuleFactory = mock(RuleFactory.class);
when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
when(mockRuleFactory.getGenerationConfig()).thenReturn(new DefaultGenerationConfig());
URL schemaContent = this.getClass().getResource("/schema/address.json");
new SchemaMapper(mockRuleFactory, new SchemaGenerator()).generate(new JCodeModel(), "Address", "com.example.package", schemaContent);
ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);
ArgumentCaptor<JsonNode> captureNode = ArgumentCaptor.forClass(JsonNode.class);
verify(mockSchemaRule).apply(eq("Address"), captureNode.capture(), capturePackage.capture(), Mockito.isA(Schema.class));
assertThat(capturePackage.getValue().name(), is("com.example.package"));
assertThat(captureNode.getValue(), is(notNullValue()));
}
示例9: generateCreatesSchemaFromSchemaAsStringInput
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Test
public void generateCreatesSchemaFromSchemaAsStringInput() throws IOException {
String schemaContent = IOUtils.toString(this.getClass().getResourceAsStream("/schema/address.json"));
final SchemaRule mockSchemaRule = mock(SchemaRule.class);
final RuleFactory mockRuleFactory = mock(RuleFactory.class);
when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
when(mockRuleFactory.getGenerationConfig()).thenReturn(new DefaultGenerationConfig());
new SchemaMapper(mockRuleFactory, new SchemaGenerator()).generate(new JCodeModel(), "Address", "com.example.package", schemaContent);
ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);
ArgumentCaptor<JsonNode> captureNode = ArgumentCaptor.forClass(JsonNode.class);
verify(mockSchemaRule).apply(eq("Address"), captureNode.capture(), capturePackage.capture(), Mockito.isA(Schema.class));
assertThat(capturePackage.getValue().name(), is("com.example.package"));
assertThat(captureNode.getValue(), is(notNullValue()));
}
示例10: getCustomRuleFactory
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
@Override
public Class<? extends RuleFactory> getCustomRuleFactory() {
return customRuleFactory;
}
示例11: getCodegenModel
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
protected JCodeModel getCodegenModel(String schema,
String targetpackage,
final String sourcetype,
final String annotationstyle,
final boolean usedoublenumbers,
final boolean includeaccessors,
final boolean includeadditionalproperties,
final String propertyworddelimiters,
String classname) throws IOException {
JCodeModel codeModel = new JCodeModel();
GenerationConfig config = new DefaultGenerationConfig() {
@Override
public boolean isGenerateBuilders() { // set config option by overriding method
return true;
}
@Override
public SourceType getSourceType() {
return SourceType.valueOf(sourcetype.toUpperCase());
}
@Override
public AnnotationStyle getAnnotationStyle() {
return AnnotationStyle.valueOf(annotationstyle.toUpperCase());
}
@Override
public boolean isUseDoubleNumbers() {
return usedoublenumbers;
}
@Override
public boolean isIncludeAccessors() {
return includeaccessors;
}
@Override
public boolean isIncludeAdditionalProperties() {
return includeadditionalproperties;
}
@Override
public char[] getPropertyWordDelimiters() {
return propertyworddelimiters.replace(" ", "").toCharArray();
}
};
AnnotatorFactory factory = new AnnotatorFactory(config);
CompositeAnnotator annotator = factory.getAnnotator(factory.getAnnotator(config.getAnnotationStyle()), factory.getAnnotator(config.getCustomAnnotator()));
SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, annotator, new SchemaStore()), new SchemaGenerator());
mapper.generate(codeModel, classname, targetpackage, schema);
return codeModel;
}
示例12: createModel
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
public void createModel(File jsonFile, String modelName) throws IOException {
//CapFirst for java classes
modelName = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
System.out.println("Model name :"+modelName);
JCodeModel codeModel = new JCodeModel();
GenerationConfig config = new DefaultGenerationConfig() {
@Override
public boolean isIncludeConstructors() {
return true;
}
@Override
public boolean isUseDoubleNumbers() {
return true;
}
@Override
public boolean isUsePrimitives() {
return true;
}
@Override
public boolean isIncludeToString() {
return false;
}
@Override
public boolean isIncludeHashcodeAndEquals() {
return false;
}
@Override
public boolean isIncludeAdditionalProperties() {
return false;
}
@Override
public Class<? extends RuleFactory> getCustomRuleFactory() {
return APXCustomRuleFactory.class;
}
};
SchemaMapper mapper = new SchemaMapper(new APXCustomRuleFactory(config, new ORMLiteAnotator(), new SchemaStore()), new SchemaGenerator());
JType m = mapper.generate(codeModel, modelName, PACKAGE_NAME + ".models", jsonFile.toURI().toURL());
File f = new File(PROJECT_SRC);
codeModel.build(f);
System.out.print("Model created at :");
System.out.println(m.fullName().replace('.', File.separatorChar) + ".java");
}
示例13: generate
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
/**
* Generates classes based on json/jsonschema.
*
* @return class name
* @throws IOException
*/
public String generate() throws IOException {
String schemaPath = this.config.getJsonSchemaPath();
if (schemas.containsKey(schemaPath)){
LOG.info("Schema already exists " + schemaPath);
return schemas.get(schemaPath);
}
JCodeModel codeModel = new JCodeModel();
URL source = new File(config.getInputPath()).toURI().toURL();
GenerationConfig generationConfig = new DefaultGenerationConfig() {
@Override
public boolean isGenerateBuilders() { // set config option by overriding metho
return true;
}
@Override
public SourceType getSourceType() {
if (JsonPath.from(source).get("$schema") != null) {
return SourceType.JSONSCHEMA;
}
return SourceType.JSON;
}
@Override
public boolean isUseLongIntegers() {
return true;
}
@Override
public boolean isUseCommonsLang3() {
return true;
}
};
SchemaMapper mapper = new SchemaMapper(
new RuleFactory(generationConfig, new GsonAnnotator(), new SchemaStore()), new SchemaGenerator());
mapper.generate(codeModel, getClassName(), config.getPackageName(), source);
codeModel.build(new File(config.getOutputPath()));
schemas.put(schemaPath, getClassName());
return getClassName();
}
示例14: SoeDefaultRule
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
public SoeDefaultRule(RuleFactory ruleFactory) {
this.ruleFactory = ruleFactory;
}
示例15: SoeTypeRule
import org.jsonschema2pojo.rules.RuleFactory; //导入依赖的package包/类
protected SoeTypeRule(RuleFactory ruleFactory) {
this.ruleFactory = ruleFactory;
}