firstthumb
firstthumb

Reputation: 4754

Create Java Pojo dynamically

How can I create Java Pojo at runtime? ASM or BCEL is required for this?

I am reading a XML file and I want to generate Pojo according to this xml.

Upvotes: 0

Views: 2609

Answers (3)

Alb
Alb

Reputation: 3681

There's a nice open source library for reading xml to objects called Xstream. Use that and you don't need to worry about manually parsing the XML or manually creating objects.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533660

You might find that generating the code in memory is much easier to work with. (ASM is very good otherwise) With generated code you just have to create the java you would need.

You can use tools like BeanShell or the Compiler API

Upvotes: 0

Teja Kantamneni
Teja Kantamneni

Reputation: 17472

There are lot of libraries available to generate classes in runtime. If you want to create a class and write it back to disk, BCEL and CGLIB is good. If you want most of them for runtime only, CGLIB is probably the best

Upvotes: 2

Related Questions