微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.jsonschema2pojo.rules.RuleFactory的实例源码

项目:GitHub    文件Jsonschema2PojoMojo.java   
@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;
    }
}
项目:GitHub    文件Jsonschema2PojoTask.java   
@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;
    }
}
项目:GitHub    文件FragmentRefIT.java   
@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));
}
项目:GitHub    文件FragmentRefIT.java   
@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));
}
项目:data-mapper    文件JsonModelGenerator.java   
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());
}
项目:GitHub    文件DefaultGenerationConfig.java   
@Override
public Class<? extends RuleFactory> getCustomruleFactory() {
    return RuleFactory.class;
}
项目:GitHub    文件Example.java   
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

    }
项目:GitHub    文件SchemaMapperTest.java   
@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()));

}
项目:GitHub    文件SchemaMapperTest.java   
@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,is(notNullValue()));

}
项目:GitHub    文件Jsonschema2PojoTask.java   
@Override
public Class<? extends RuleFactory> getCustomruleFactory() {
    return customruleFactory;
}
项目:GitHub    文件Arguments.java   
@Override
public Class<? extends RuleFactory> getCustomruleFactory() {
    return customruleFactory;
}
项目:sc-generator    文件JsonSchemaController.java   
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 SchemaGenerator());
    mapper.generate(codemodel,classname,targetpackage,schema);
    return codemodel;
}
项目:APX    文件Operations.java   
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 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");

    }
项目:rarc    文件JsonCodegen.java   
/**
 * 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(),getClassName(),config.getPackageName(),source);
    codemodel.build(new File(config.getoutputPath()));

    schemas.put(schemaPath,getClassName());
    return getClassName();
}
项目:jsonschema2pojo-bacta    文件SoeDefaultRule.java   
public SoeDefaultRule(RuleFactory ruleFactory) {
    this.ruleFactory = ruleFactory;
}
项目:jsonschema2pojo-bacta    文件SoeTypeRule.java   
protected SoeTypeRule(RuleFactory ruleFactory) {
    this.ruleFactory = ruleFactory;
}
项目:GitHub    文件SchemaMapperTest.java   
@Test
public void generateCreatesSchemaFromExampleJsonWhenInjsonMode() throws IOException {

    URL schemaContent = this.getClass().getResource("/schema/address.json");

    ObjectNode schemaNode = JsonNodeFactory.instance.objectNode();

    final SchemaRule mockSchemaRule = mock(SchemaRule.class);

    final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
    when(mockGenerationConfig.getSourceType()).thenReturn(SourceType.JSON);

    final SchemaGenerator mockSchemaGenerator = mock(SchemaGenerator.class);
    when(mockSchemaGenerator.schemaFromExample(schemaContent)).thenReturn(schemaNode);

    final RuleFactory mockRuleFactory = mock(RuleFactory.class);
    when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
    when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);

    new SchemaMapper(mockRuleFactory,mockSchemaGenerator).generate(new Jcodemodel(),schemaContent);

    ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);

    verify(mockSchemaRule).apply(eq("Address"),eq(schemaNode),is("com.example.package"));

}
项目:GitHub    文件SchemaMapperTest.java   
@Test
public void generateCreatesSchemaFromExampleJSONAsstringinput() throws IOException {

    String jsonContent = IoUtils.toString(this.getClass().getResourceAsstream("/example-json/user.json"));

    ObjectNode schemaNode = JsonNodeFactory.instance.objectNode();

    final SchemaRule mockSchemaRule = mock(SchemaRule.class);

    final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
    when(mockGenerationConfig.getSourceType()).thenReturn(SourceType.JSON);

    final SchemaGenerator mockSchemaGenerator = mock(SchemaGenerator.class);
    when(mockSchemaGenerator.schemaFromExample(new ObjectMapper().readTree(jsonContent))).thenReturn(schemaNode);

    final RuleFactory mockRuleFactory = mock(RuleFactory.class);
    when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
    when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);

    new SchemaMapper(mockRuleFactory,"User",jsonContent);

    ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);

    verify(mockSchemaRule).apply(eq("User"),is("com.example.package"));
}
项目:GitHub    文件GenerationConfig.java   
/**
 * Gets the 'customruleFactory' configuration option.
 *
 * @return An Rule Factory that will be used for the creation of generation
 *         rules.
 */
Class<? extends RuleFactory> getCustomruleFactory();
项目:GitHub    文件SchemaMapper.java   
/**
 * Create a schema mapper with the given {@link RuleFactory}.
 *
 * @param ruleFactory
 *            A factory used by this mapper to create Java type generation
 *            rules.
 * @param schemaGenerator
 *            the generator that this mapper will use if the config dictates
 *            that the input documents are plain json (not json schema)
 */
public SchemaMapper(RuleFactory ruleFactory,SchemaGenerator schemaGenerator) {
    this.ruleFactory = ruleFactory;
    this.schemaGenerator = schemaGenerator;
}
项目:GitHub    文件SchemaMapper.java   
/**
 * Create a schema mapper with the default {@link RuleFactory}
 * implementation.
 *
 * @see RuleFactory
 */
public SchemaMapper() {
    this(new RuleFactory(),new SchemaGenerator());
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。