commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: ClassCastException with betwixt 0.6
Date Wed, 15 Dec 2004 09:41:53 GMT
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message