Need expert advice on parsing a string into java beans



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="edmond.wong@xxxxxxxxxxx"}{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
.



Relevant Pages

  • Re: invoking a method
    ... Getters and Setters are used to encapsulate the ... to a string and add it to another string. ... the same as "inserting" it... ...
    (comp.lang.cobol)
  • Re: Reflection in 1.1 and 2.0 - generic, fast copy delegate?
    ... Your delegate solution is is still significantly more efficient that reflection. ... Also you need permissions to emit code with the LCG version whereas using delegates does not appear to require permissions beyond those for public reflection and so you can have a fast solution even in low trust environments. ... private string _firstName; ...
    (microsoft.public.dotnet.framework.clr)
  • Re: EJB3 Newbie & Persistence
    ... private String name; ... CustomerCMP customer; ... public void setAddress{ ...
    (comp.lang.java.beans)
  • Re: Reflection in 1.1 and 2.0 - generic, fast copy delegate?
    ... private string _firstName; ... private int _age; ... I'm well aware of LCG, and in fact, I'm not even sure why you need it in 2.0. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: variable length fields for flexibility in subroutines
    ... private string _IntBlock; ... public string IBreturn ... public string IBstreet ...
    (comp.lang.cobol)