Need expert advice on parsing a string into java beans

Discussion in 'Java' started by Edmond wong, Apr 25, 2005.

  1. Edmond wong

    Edmond wong Guest

    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=""}{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
     
    Edmond wong, Apr 25, 2005
    #1
    1. Advertising

  2. Edmond wong

    farseer Guest

    couldn't you use java.beans.XMLEncoder and XMLDecoder or Castor to
    this?
     
    farseer, Apr 25, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Willans

    J2EE + Beans advice required

    James Willans, Jun 24, 2004, in forum: Java
    Replies:
    1
    Views:
    305
    Phillip Mills
    Jun 24, 2004
  2. Torsten Schmeissel
    Replies:
    0
    Views:
    431
    Torsten Schmeissel
    Apr 29, 2005
  3. shapper
    Replies:
    7
    Views:
    318
    shapper
    Feb 27, 2007
  4. polilop
    Replies:
    1
    Views:
    274
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Jan 14, 2007
  5. andyau
    Replies:
    4
    Views:
    118
    andyau
    Mar 31, 2008
Loading...

Share This Page