BeanWriter beanWriter = new BeanWriter(stringWriter);
beanWriter.write(bean);
stringWriter.flush();
String xml = "<?xml version='1.0'?>" + stringWriter.toString();
BeanReader reader = new BeanReader();
reader.registerBeanClass( PersonBean.class );
bean = (PersonBean) reader.parse(new StringReader(xml));
assertEquals("Person age wrong", 21 , bean.getAge());
assertEquals("Person name wrong", "Samual Smith" , bean.getName());
// test now with attributes for primitives
bean = new PersonBean(19, "John Smith");
stringWriter = new StringWriter();
beanWriter = new BeanWriter(stringWriter);
beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
beanWriter.write(bean);
stringWriter.flush();
xml = "<?xml version='1.0'?>" + stringWriter.toString();
reader = new BeanReader();
reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
reader.registerBeanClass( PersonBean.class );
bean = (PersonBean) reader.parse(new StringReader(xml));
assertEquals("[Attribute] Person age wrong", 19 , bean.getAge());
assertEquals("[Attribute] Person name wrong", "John Smith" , bean.getName());
}