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;       
   }

}
2
  • 1
    stackoverflow.com/questions/23217891/… Commented Oct 6, 2014 at 11:14
  • @ares your answer was right. write your answer to accept Commented Oct 6, 2014 at 12:07

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

No, I want something like decompilation
Thank you. Best way is decompiling
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.
Yes, you are right, but I need the object at runtime
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.
0

Try write-it-once for custom generations

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.