@Override public SourceType getSourceType() { return SourceType.valueOf(sourceType.toUpperCase()); }
@Override public SourceType getSourceType() { return sourceType; }
/** * 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(); }
public JsonGenerationConfig setSourceType(SourceType sourceType) { this.sourceType = sourceType; return this; }
/** * Generates Java classes in targetPath directory given a JSON instance * document. * * @param className name of the top-level class used for the generated model * @param packageName package name for generated model classes * @param instanceUrl url for the JSON message containing instance data * @param targetPath directory where class source will be generated * @throws Exception failure during model generation */ public JCodeModel generateFromInstance(final String className, final String packageName, final URL instanceUrl, final File targetPath) throws Exception { config.setSourceType(SourceType.JSON); return generate(className, packageName, instanceUrl, targetPath); }
/** * Sets the 'sourceType' property of this class * * @param sourceType * The type of input documents that will be read * <p> * Supported values: * <ul> * <li><code>jsonschema</code></li> * <li><code>json</code></li> * <li><code>yamlschema</code></li> * <li><code>yaml</code></li> * </ul> */ public void setSourceType(SourceType sourceType) { this.sourceType = sourceType; }