1

I´m using the jsonschema2pojo-core to parse from JSON to POJO. The thing is I´d like to set the annotationStyle to GSON. (default is Jackson).

Any idea?

Thanks a lot.

jkrlos
  • 133
  • 1
  • 2
  • 11

2 Answers2

0

Implement GenerationConfig.java or extend DefaultGenerationConfig.java

    ...
    @Override
    public AnnotationStyle getAnnotationStyle() {
        return AnnotationStyle.GSON;
    }
    ...
ejohansson
  • 2,832
  • 1
  • 23
  • 30
0

If it helps someone, full implementation:

        public void convertJsonToJavaClass(String inputJsonStr, File outputJavaClassDirectory,
                                   String packageName, String javaClassName)
        throws IOException {
    JCodeModel jcodeModel = new JCodeModel();

    GenerationConfig config = new DefaultGenerationConfig() {
        @Override
        public boolean isGenerateBuilders() {
            return true;
        }
        @Override
        public SourceType getSourceType() {
            return SourceType.JSON;
        }
        @Override
        public AnnotationStyle getAnnotationStyle() {
            return AnnotationStyle.GSON;
        }
    };

    SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new GsonAnnotator(config),
            new SchemaStore()), new SchemaGenerator());
    mapper.generate(jcodeModel, javaClassName, packageName, inputJsonStr);

    jcodeModel.build(outputJavaClassDirectory);

}
SydMK
  • 425
  • 4
  • 12