commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edmond Wong <wyw...@pacbell.net>
Subject BeWixt's bug where it cannot generate XML if the root class only contain a class parameter?
Date Sat, 23 Apr 2005 05:21:36 GMT
Hi,

I am using the nightly build of the bewixt library, and got the follow 
problem on the output where the xml document is not generated.  The 
problem happen when I have a root class PersonBean where it only 
contains a Book class for its parameter:

import java.io.StringWriter;
import org.apache.commons.betwixt.io.BeanWriter;

Public class WriteExampleApp {
    public static void main(String[] args) throws Exception {            
   
        PersonBean pb = new PersonBean();
        pb.setBook(new Book("Edmond Book", "Edmond"));   
        System.out.println(pb);       
        StringWriter outputWriter = new StringWriter();       
        outputWriter.write("<?xml version='1.0' ?>\n");             
        BeanWriter beanWriter = new BeanWriter(outputWriter);
        beanWriter.enablePrettyPrint();
        beanWriter.getBindingConfiguration().setMapIDs(true);      
        
beanWriter.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(true);
        beanWriter.setWriteEmptyElements(false);
        beanWriter.write(pb);       
        System.out.println(outputWriter.toString());       
    }
}

The output:
PersonBean@f6a746[book=Book@13e8d89[name_of_book=Edmond Book,author=Edmond]]
<?xml version='1.0' ?>

PersonBean.class:

import org.apache.commons.lang.builder.ToStringBuilder;

public class PersonBean implements java.io.Serializable {
    private Book book = new Book();
    public PersonBean() {
    }
    public PersonBean(Book book) {
        super();
        this.book = book;
    }
    public Book getBook() {
        return this.book;
    }
    public void setBook(Book book) {
        this.book = book;
    }
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

Book.class:

import org.apache.commons.lang.builder.ToStringBuilder;

public class Book implements java.io.Serializable {
    String name_of_book;
    String author;
    public Book() {
    }
    public Book(String name_of_book, String author) {
        super();
        this.name_of_book = name_of_book;
        this.author = author;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getName_of_book() {
        return name_of_book;
    }
    public void setName_of_book(String name_of_book) {
        this.name_of_book = name_of_book;
    }
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

Thanks,

Edmond

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message