1

我需要将接口的实现添加到填充的JCodeModel对象,然后.java使用codeModel.build("FilePath");. 我正在使用jsonschema2pojo库来创建JCodeModel对象。

代码是这样的:

JCodeModel codeModel = new JCodeModel();

GenerationConfig config = new DefaultGenerationConfig() {
    @Override
        public SourceType getSourceType() {
            return SourceType.JSON;
            }
        };

SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());

mapper.generate(codeModel, action, packageName, apiResultAsString);

codeModel.build(new File("src").getAbsoluteFile());

可以选择JCodeModel在类()中实现接口_implements(),但我无法在上面的代码中使用它(请参阅代码中的以下注释):

// _implements() works on a JDefinedClass, 
// To get JDefinedClass we need to run _getClass() on a generated codeModel (after mapper.generate() ), 
// But What should be provided as a fully qualiflied class name for the argumanet of _getClass(),
// where or .java file isn't built yet, so the class file.

codeModel._getClass("com.foo.Bar")._implements(JsonResponseObject.class);
4

0 回答 0