0

I've created a pojo object in runtime using javassist. I want to write it to a java file. I don't want to write a lot of code for this job. Is there any utility for doing this?

for example the output should be something like this :

@Annotations
public class MyClass{
   @Id
   private String id; 

   @Column    
   public String getId(){
       return id;
   }

   public void setId(String id){
       this.id=id;       
   }

}
Pooya
  • 4,385
  • 6
  • 45
  • 73

2 Answers2

1

If you're using javassist I believe you cannot write source. Javassist works off byte code only so you can write a class file using CtClass.writeFile().

I found this on another answer https://stackoverflow.com/a/122209/4097877 this should help. I've not had a proper read through as yet but by the description it looks like it will solve your problem.

Community
  • 1
  • 1
  • No, I want something like decompilation – Pooya Oct 06 '14 at 11:16
  • Thank you. Best way is decompiling – Pooya Oct 06 '14 at 12:13
  • So you'll generate the byte code with javassist and then generate a class file and then decompile it. You might as well generate the source directly instead of the extra step. I did a brief Google but wasn't able to find any java libraries which provide decompilation so you'll have to run the command as a separate process I guess. – Arun Ramakrishnan Oct 06 '14 at 12:32
  • Yes, you are right, but I need the object at runtime – Pooya Oct 06 '14 at 13:51
  • Oh OK I see. That's fine then, hope you find what you're looking for! I'm not sure on any more details on the same. – Arun Ramakrishnan Oct 06 '14 at 13:53
0

Try write-it-once for custom generations

Atmega
  • 131
  • 4