I was quite excited that the problem may have been found however I
changed the code so that the configuration object is shared between
the writer and reader and I am still receiving a null object back from
the reader. The new code is listed below.
The output when running the program is:
out: <?xml version='1.0'?><PersonBean age="24" name="ryan c" id="1"/>
null
I am still at a loss why this simple example is not working. The only
thing I can think of (unless someone sees a problem with the code I am
using below) is that my jar versions are not correct. However I used
the same jars that maven appears to use when running regression (which
passes). Any ideas on where to go next?
Thanks,
ryan
public static final void main(String args[]) throws Exception{
StringWriter out = new StringWriter();
out.write("<?xml version='1.0'?>");
BeanWriter writer = new BeanWriter(out);
IntrospectionConfiguration configuration =
writer.getXMLIntrospector().getConfiguration();
configuration.setAttributesForPrimitives(true);
configuration.setWrapCollectionsInElement(false);
writer.setWriteEmptyElements( true );
PersonBean personBean = new PersonBean();
personBean.setName("ryan c");
personBean.setAge(24);
writer.write(personBean);
System.out.println("out: " + out);
StringReader xmlReader = new StringReader(out.toString());
BeanReader reader = new BeanReader();
reader.getXMLIntrospector().setConfiguration(configuration);
reader.registerBeanClass(PersonBean.class);
PersonBean person = (PersonBean) reader.parse(xmlReader);
// send bean to system out
System.out.println(person);
}
On Wed, 15 Dec 2004 09:41:53 +0000, robert burrell donkin
<[EMAIL PROTECTED]> wrote:
> hi ryan
>
> i'm afraid you're going to kick yourself ;)
>
> On 15 Dec 2004, at 05:45, Ryan Crumley wrote:
>
> <snip>
>
> > public class TestBetwixt {
> > public static final void main(String args[]) throws Exception{
> > StringWriter out = new StringWriter();
> > out.write("<?xml version='1.0'?>");
> >
> > BeanWriter writer = new BeanWriter(out);
> > writer.setWriteEmptyElements( true );
> >
> > PersonBean personBean = new PersonBean();
> > personBean.setName("ryan c");
> > personBean.setAge(24);
> >
> > writer.write(personBean);
> >
> > System.out.println("out: " + out);
> >
> >
> > StringReader xmlReader = new StringReader(out.toString());
> >
> > BeanReader reader = new BeanReader();
> >
> > reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitiv
> > es(true);
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> this line means that the writing is configured to write primitives as
> elements but the reading configuration is expecting them to be
> attributes.
>
> a couple of related tips:
>
> * using the same IntrospectionConfiguration instance for the reader and
> writer will ensure that the configurations are identical;
> * XMLIntrospector caches the results of introspection (which takes
> quite a bit of time) and so as long as readers and writers share the
> same configuration, you'll get better performance if they share the
> same instance;
>
> - robert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]