org.jsonschema2pojo.DefaultGenerationConfig Java Examples

The following examples show how to use org.jsonschema2pojo.DefaultGenerationConfig. 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);
}
 
Example #2
Source File: SchemaHelper.java    From springmvc-raml-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a generation config with the supplied parameters. If any of these
 * parameters are supplied null, it will use the value defined in the
 * default configuration
 *
 * @param generateBuilders
 *            Enables or disables
 *            {@link GenerationConfig#isGenerateBuilders()}
 * @param includeAdditionalProperties
 *            Enables or disables
 *            {@link GenerationConfig#isIncludeAdditionalProperties()}
 * @param includeDynamicAccessors
 *            Enables or disables
 *            {@link GenerationConfig#isIncludeDynamicAccessors()}
 * @param useLongIntegers
 *            Enables or disables
 *            {@link GenerationConfig#isUseLongIntegers()}
 * @return The GenerationConfig
 */
public static GenerationConfig getGenerationConfig(Boolean generateBuilders, Boolean includeAdditionalProperties,
		Boolean includeDynamicAccessors, Boolean useLongIntegers) {
	return new DefaultGenerationConfig() {

		@Override
		public boolean isGenerateBuilders() { // set config option by
												// overriding method
			if (generateBuilders != null) {
				return generateBuilders;
			} else {
				return true;
			}
		}

		@Override
		public boolean isIncludeAdditionalProperties() {
			if (includeAdditionalProperties != null) {
				return includeAdditionalProperties;
			} else {
				return false;
			}
		}

		@Override
		public boolean isIncludeDynamicAccessors() {
			if (includeDynamicAccessors != null) {
				return includeDynamicAccessors;
			} else {
				return false;
			}
		}

		@Override
		public boolean isUseLongIntegers() {
			if (useLongIntegers != null) {
				return useLongIntegers;
			} else {
				return super.isUseLongIntegers();
			}
		}
	};
}