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.
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.
Implement GenerationConfig.java or extend DefaultGenerationConfig.java
...
@Override
public AnnotationStyle getAnnotationStyle() {
return AnnotationStyle.GSON;
}
...
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);
}