Need expert advice on parsing a string into java beans

E

Edmond wong

Hi,

I wrote the code to convert Java bean (using recursion and reflection)
to a string, and the string is:

ie. String text = MyUtil.toText(book);

text={book:Book={{name:java.lang.String="My
Book"}{author:Author={{name:java.lang.String="Edmond
Wong"}{email:java.lang.String="(e-mail address removed)"}{address:java.lang.String="333
S. Hope
St"}}}{price:double=49.99}{chapters:java.util.Vector={{chapter:Chapter={{no:int=1}{name:java.lang.String="Act
I"}}}{chapter:Chapter={{no:int=2}{name:java.lang.String="Act
II"}}}{chapter:Chapter={{no:int=3}{name:java.lang.String="Act III"}}}}}}}

However, I am having a hard time using recursion to parse the string
back to the Java beans. Any ideas?

The Java Beans have the followingstructure:

public class Book implements java.io.Serializable{
private String name;
private Author author;
private double price;
private Vector chapters;
// Setters and Getters
}

public abstract class AbstractAuthor implements java.io.Serializable {
private String address;
// Setters and Getters
}

public class Author extends AbstractAuthor {
private String name;
private String email;
// Setters and Getters
}

public class Chapter implements java.io.Serializable {
int no;
String name;
// Setters and Getters
}



Thanks,

Edmond
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top