[jdom-interest] JDOM Elements from simple Java data objects

William BC Crandall bc.crandall at earthlink.net
Mon Jul 12 15:45:19 PDT 2004

Hello JDOMers,

I'm using Hibernate to get simple data objects out of a DB.
Is there an existing tool to turn such get/set objects into
JDOM Elements with the same structure? 

That is, somthing that would generate an address element:

  <id></id>  <!-- using toString -->

given an object of the class:

public class Address implements Serializable {
  private Integer id;
  private String street;
  private String city;

  public Address() {

  public Integer getId() {
    return id;
  public void setId(Integer newId) {
    this.id = newId;

  public String getStreet() {
    return street;
  public void setStreet(String newStreet) {
    this.street = newStreet;

  public String getCity() {
    return city;
  public void setCity(String newCity) {
    this.city = newCity;

I know this can be done "by hand," with a series of Element, 
new Element(); setText(); addContent(); statements, but was
looking for something a bit more automatic.

I can't believe I'm the first to want to do this, but I've not
found any references in the FAQ, mail archives, or with Google.

Many thanks for any suggestions.

Best to all,

William BC Crandall
bc.crandall [around] earthlink.net

More information about the jdom-interest mailing list