views:

52

answers:

4

What libraries are available that can do something like

public class Person {
  private Long id;
  private Name; 
  private List<Long> associations;

  // accessors
}

public class Name {
  private String first;
  private String last; 

  // accessors
}

into something like

id=1
associations=1,2,3,4,5
name.first=Franz
name.last=See

[EDIT] And If there's no library to do that, what's a good way to do it? :-)

Thanks, Franz

A: 

Well I think instead of using any external library you can do it yourself just add getters and setters in your javabeans and override to string method of it and then you can form the string as you want.Then only task remaining is to write that string into one file, thats it!!!!!

Rupeshit
True. But this seems to be a pretty common thing that im guessing somebody has already done something like this and all i have to do is call something like SomeUtil.toProperties(...) :-)
Franz See
+2  A: 

I doubt there's a library for that since common way to serialize beans is into XML. You may write simple library yourself using Java Reflection API to get list of properties and extract their values. It would be more common solution than making custom toString() for any class you may need to serialize.

Vadim Fedorov
A: 

Maby check this out: http://java.sun.com/developer/technicalArticles/Programming/serialization/

But if you want to use a real Database i would recommend hibernate. http://www.hibernate.org/

Till
A: 

Well, you can go check how XMLEncoder extract field names and values from object, and try to rewrite it to output properties files. I think that, by replacing xml output by properties output, you can get a fairly good properties creator. Notice, as an added benefit, that the same goes for properties reading using an equivalent opf XMLDecoder.

Riduidel