• Post Reply Bookmark Topic Watch Topic
  • New Topic

Propose methods for reading all instance variables of object.  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to realize some alternative case serialization and deserialization objects in Java.
1) It is difficult task, but how can i to collect all instance variables of class in order to write it to file?
Please, help me.
I need you offers and advices. Simply propose some destination.
This is for studying purposes. But, i am begginer, so i have nothing ideas.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
who has told you to do this?
 
Robert Raps
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:who has told you to do this?

My teacher. So far i think to make something like XML parser, but i haven't know yet in some way to realize reading Instance Variables in order to get them for writing? What java instruments do help me?? Please point me some destination, and i try to deal with it.
This easiest way:http://www.kodejava.org/examples/406.html ??
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to do that with XML or similar, you can make your objects fulfil the Bean pattern.
Or you can give them matching toString and Foo(String) constructors. Or valueOf(String) factory methods.
The XML solution is probably better. I think there is a tutorial here.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I think there is a tutorial here.

And more specifically, here. The 'Long-term persistence' section also shows you how to use XMLEncoder, which is probably a good place to start, because it'll save you the business of having to write a lot of reflection code.

Not being an expert, I'm not sure how comprehensive it is in dealing with objects that contain other objects that aren't defined specifically as Beans (or as Serializable) though. This page might help to answer some of those questions.

Just to let you know: this is not a simple task; so don't be surprised if you're doing a LOT of reading early on.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!