org.jsonschema2pojo.Jackson2Annotator Java Examples

The following examples show how to use org.jsonschema2pojo.Jackson2Annotator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenApi2JaxRs.java    From apicurio-studio with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a Java Bean class for the given bean info.  The bean info should
 * have a name, package, and JSON Schema.  This information will be used to 
 * generate a POJO.
 * @param bean
 * @param info 
 * @param codeWriter
 * @throws IOException
 */
private void generateJavaBean(CodegenJavaBean bean, CodegenInfo info, IndexedCodeWriter codeWriter) throws IOException {
    JCodeModel codeModel = new JCodeModel();
    GenerationConfig config = new DefaultGenerationConfig() {
        @Override
        public boolean isUsePrimitives() {
            return false;
        }
        @Override
        public boolean isIncludeHashcodeAndEquals() {
            return false;
        }
        @Override
        public boolean isIncludeAdditionalProperties() {
            return false;
        }
        @Override
        public boolean isIncludeToString() {
            return false;
        }
    };

    SchemaMapper schemaMapper = new SchemaMapper(
            new JaxRsRuleFactory(config, new Jackson2Annotator(config), new SchemaStore() {
                @Override
                public Schema create(Schema parent, String path, String refFragmentPathDelimiters) {
                    String beanClassname = schemaRefToFQCN(path);
                    for (CodegenJavaBean cgBean : info.getBeans()) {
                        String cgBeanFQCN = cgBean.getPackage() + "." + StringUtils.capitalize(cgBean.getName());
                        if (beanClassname.equals(cgBeanFQCN)) {
                            Schema schema = new Schema(classnameToUri(beanClassname), cgBean.get$schema(), null);
                            JType jclass = codeModel._getClass(beanClassname);
                            if (jclass == null) {
                                jclass = codeModel.directClass(beanClassname);
                            }
                            schema.setJavaType(jclass);
                            return schema;
                        }
                    }
                    System.out.println("!!!!! :: " + beanClassname);
                    // TODO if we get here, we probably want to return an empty schema
                    return super.create(parent, path, refFragmentPathDelimiters);
                }
            }),
            new SchemaGenerator());
    String source = mapper.writeValueAsString(bean.get$schema());
    schemaMapper.generate(codeModel, bean.getName(), bean.getPackage(), source);
    codeModel.build(codeWriter);
}