• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SchemaMapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jsonschema2pojo.SchemaMapper的典型用法代码示例。如果您正苦于以下问题:Java SchemaMapper类的具体用法?Java SchemaMapper怎么用?Java SchemaMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SchemaMapper类属于org.jsonschema2pojo包,在下文中一共展示了SchemaMapper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: nestedSelfRefsInStringContentWithoutParentFile

import org.jsonschema2pojo.SchemaMapper; //导入依赖的package包/类
@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"));
    
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:SelfRefIT.java


示例2: generate

import org.jsonschema2pojo.SchemaMapper; //导入依赖的package包/类
private JCodeModel generate(final String className, final String packageName,
        final URL inputUrl, final File targetPath) throws Exception {

    final SchemaMapper mapper = createSchemaMapper();
    final JCodeModel codeModel = new JCodeModel();
    mapper.generate(codeModel, className, packageName, inputUrl);
    try (PrintStream status = new PrintStream(new ByteArrayOutputStream())) {
        codeModel.build(targetPath, status);
    }

    return codeModel;
}
 
开发者ID:fabric8io,项目名称:data-mapper,代码行数:13,代码来源:JsonModelGenerator.java


示例3: createSchemaMapper

import org.jsonschema2pojo.SchemaMapper; //导入依赖的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());
}
 
开发者ID:fabric8io,项目名称:data-mapper,代码行数:13,代码来源:JsonModelGenerator.java


示例4: main

import org.jsonschema2pojo.SchemaMapper; //导入依赖的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

    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:Example.java


示例5: createModel

import org.jsonschema2pojo.SchemaMapper; //导入依赖的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");

    }
 
开发者ID:othreecodes,项目名称:APX,代码行数:60,代码来源:Operations.java


示例6: generate

import org.jsonschema2pojo.SchemaMapper; //导入依赖的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();
}
 
开发者ID:qameta,项目名称:rarc,代码行数:49,代码来源:JsonCodegen.java



注:本文中的org.jsonschema2pojo.SchemaMapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Expression类代码示例发布时间:2022-05-23
下一篇:
Java PacketKexInit类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap