commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurent ForĂȘt <laurent.fo...@gmail.com>
Subject [Betwixt] BeanReader and NameMapper
Date Fri, 20 Jan 2006 10:06:14 GMT
Hello,

My question is : Can we apply the same NameMapper to a bean reader ?

I thought it was possible but I can not read a bean that I have
serialized with the beanWriter using my own NameMapper.
Indeed the following code throws a NullPointerException at the last line:

        Writer writer = new StringWriter();
        writer.write(XML_HEADER);
        BeanWriter beanWriter = new BeanWriter(writer);
        beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        beanWriter.getBindingConfiguration().setMapIDs(false);
        beanWriter.enablePrettyPrint();

        beanWriter.getXMLIntrospector().getConfiguration().setElementNameMapper(new
MyOwnNameMapper());

        MyBean myBean = new MyBean();
        myBean.setValue("toto");
        beanWriter.write(myBean);

        System.out.println(writer.toString());
       // At this point My bean has a good looking element name

        MyBean myBean2 =null;
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(MyBean.class);

        beanReader.getXMLIntrospector().getConfiguration().setElementNameMapper(new
MyOwnNameMapper());

        ref2 = (CDAReference) beanReader.parse(new
StringReader(writer.toString()));
        assertEquals(ref.getValue(), ref2.getValue());


Help wanted.

Laurent.

---------------------------------------------------------------------
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