1

I need to add an implementaion of an interface to a populated JCodeModel object, before saving it to a .java file using codeModel.build("FilePath");. I'm using jsonschema2pojo library to create JCodeModel object.

The code is this:

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());

The JCodeModel has the option to implement Interface in a class ( _implements() ), But I can't utilize it in the above code (refer to the comments below in the code):

// _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);
DummyBeginner
  • 411
  • 10
  • 34

0 Answers0