@Override @SuppressWarnings("unchecked") public Class<? extends Annotator> getCustomAnnotator() { if (isNotBlank(customAnnotator)) { try { return (Class<? extends Annotator>) Class.forName(customAnnotator); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } else { return NoopAnnotator.class; } }
/** * Sets the 'customAnnotator' property of this class * * @param customAnnotator * A custom annotator to use to annotate the generated types */ @SuppressWarnings("unchecked") public void setCustomAnnotator(String customAnnotator) { if (isNotBlank(customAnnotator)) { try { this.customAnnotator = (Class<? extends Annotator>) Class.forName(customAnnotator); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } else { this.customAnnotator = NoopAnnotator.class; } }
@Test @SuppressWarnings("unchecked") public void classIsCreatedFromFullyQualifiedClassName() { Class<Annotator> clazz = converter.convert(Annotator.class.getName()); assertThat(clazz, is(equalTo(Annotator.class))); }
/** * * @param config * @return */ private static Annotator getAnnotator(GenerationConfig config) { Annotator coreAnnotator = new AnnotatorFactory().getAnnotator(config.getAnnotationStyle()); if(config.getCustomAnnotator() != null){ Annotator customAnnotator = new AnnotatorFactory().getAnnotator(config.getCustomAnnotator()); return new CompositeAnnotator(coreAnnotator, customAnnotator); } return coreAnnotator; }
private Annotator getAnnotator() { ArrayList<Annotator> annotators = new ArrayList<>(); if (config.isGsonSupport()) { annotators.add(new GsonAnnotator()); } if (config.isJacksonSupport()) { annotators.add(new Jackson2Annotator()); } CompositeAnnotator ac = new CompositeAnnotator(annotators.toArray(new Annotator[annotators.size()])); return ac; }
private void generateModelSources(JCodeModel codeModel, ApiBodyMetadata body, File rootDir, GenerationConfig config, Annotator annotator) { boolean build = false; if (codeModel == null) { this.getLog().info("Generating Model object for: " + body.getName()); build = true; if (config == null && annotator == null) { codeModel = body.getCodeModel(); } else { codeModel = body.getCodeModel(resolvedSchemaLocation, basePackage + NamingHelper.getDefaultModelPackage(), config, annotator); } } if (build && codeModel != null) { buildCodeModelToDisk(codeModel, body.getName(), rootDir); } }
@Override public Class<? extends Annotator> getCustomAnnotator() { return customAnnotator; }
public APXCustomRuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) { super(generationConfig, annotator, schemaStore); }
private static Annotator requireAnnotator(AnnotationStyle annotationStyle) { checkState(ANNOTATOR_SUPPLIER_INDEX.containsKey(annotationStyle), "Illegal annotation style: %s", annotationStyle); return ANNOTATOR_SUPPLIER_INDEX.get(annotationStyle).get(); }
/** * Create a new rule factory with the given generation config options. * * @param generationConfig * The generation config options for type generation. These * config options will influence the java code generated by rules * created by this factory. * @param annotator * the annotator used to mark up Java types with any annotations * that are required to build JSON compatible types * @param schemaStore * the object used by this factory to get and store schemas */ public RuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) { this.generationConfig = generationConfig; this.annotator = annotator; this.schemaStore = schemaStore; this.nameHelper = new NameHelper(generationConfig); }
/** * Builds a JCodeModel for this body * * @param basePackage The package we will be using for the domain objects * @param schemaLocation The location of this schema, will be used to create absolute URIs for $ref tags eg "classpath:/" * @param config JsonSchema2Pojo configuration. if null a default config will be used * @param annotator JsonSchema2Pojo annotator. if null a default annotator will be used * @return built JCodeModel */ public JCodeModel getCodeModel(String basePackage, String schemaLocation, GenerationConfig config, Annotator annotator) { if (type != null) { return codeModel; } else { return SchemaHelper.buildBodyJCodeModel(schemaLocation, basePackage, name, schema, config, annotator); } }
/** * Gets the annotator that will in apply annotations to the generated code * to allow correct serialization and deserialization, according to the * chosen annotation style. * * @return an annotator that can annotate various code constructs for JSON * support */ public Annotator getAnnotator() { return annotator; }
/** * The annotator used to mark up Java types with any annotations that are * required to build JSON compatible types * * @param annotator * the annotator */ public void setAnnotator(final Annotator annotator) { this.annotator = annotator; }