我正在使用jsonschema2pojo核心来从JSON解析到POJO。问题是我想将注解样式设置为GSON。(默认值为Jackson)。有什么想法吗?非常感谢.
ldioqlga1#
实施GenerationConfig.java或扩展DefaultGenerationConfig.java
... @Override public AnnotationStyle getAnnotationStyle() { return AnnotationStyle.GSON; } ...
8wtpewkr2#
如果它能帮助别人,全面实施:
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); }
2条答案
按热度按时间ldioqlga1#
实施GenerationConfig.java或扩展DefaultGenerationConfig.java
8wtpewkr2#
如果它能帮助别人,全面实施: