Package org.apache.commons.betwixt.io

Examples of org.apache.commons.betwixt.io.BeanReader


           
       xmlAssertIsomorphicContent(parseString(expected), parseString(xml));
    }  
   
    public void testReadCategories() throws Exception {
        BeanReader beanReader = new BeanReader();
        beanReader.getXMLIntrospector().setConfiguration(categoriesIntrospectionConfiguration);
        beanReader.setBindingConfiguration(noIDsBindingConfiguration);
        beanReader.registerBeanClass(Categories.class);

        String xml = "<?xml version='1.0'?><Categories>" +
            "<Category><Name>Runs</Name></Category>" +
            "<Category><Name>Innings</Name></Category>" +
            "<Category><Name>Dismissals</Name></Category>" +
            "<Category><Name>High Score</Name></Category>" +
            "<Category><Name>Average</Name></Category>" +
            "</Categories>";
      
       StringReader in = new StringReader(xml);
      
       Categories bean = (Categories) beanReader.parse(in);   
      
       assertEquals("5 categories", 5, bean.size());
      
       Iterator it = bean.getCategories()
       assertEquals("Runs category", new Category("Runs"), it.next());
View Full Code Here


        String xml = "<?xml version='1.0'?><ArrayListExtender><another>Whatever</another>" +
    "<Long>11</Long><Long>12</Long><Long>13</Long></ArrayListExtender>";

        StringReader in = new StringReader( xml );
       
        BeanReader reader = new BeanReader();
        reader.getBindingConfiguration().setMapIDs( false );

        reader.registerBeanClass( ArrayListExtender.class );
        ArrayListExtender bean = (ArrayListExtender) reader.parse( in );
       
        assertEquals("Whatever", bean.getAnother());
    }
View Full Code Here

        BeanWriter beanWriter = new BeanWriter(outputWriter);
        beanWriter.setEndOfLine("\n");
        beanWriter.enablePrettyPrint();
        beanWriter.getBindingConfiguration().setMapIDs(true);
        beanWriter.write(map);
        BeanReader beanReader = new BeanReader();
       
        // Configure the reader
        beanReader.registerBeanClass(MapBean.class);
        StringReader xmlReader = new StringReader(outputWriter.toString());
       
        //Parse the xml
        MapBean result = (MapBean) beanReader.parse(xmlReader);
        assertNotNull("Should have deserialized a MapBean but got null.", result);
        assertEquals("Should have gotten the same value back from the Map after deserializing that was put in.",
                map.getValues().get(key),
                result.getValues().get(key));
View Full Code Here

                    parseString(xml),
                    parseString(out.toString()),
                    true);
       
        // now we'll test reading via round tripping
        BeanReader reader = new BeanReader();
        reader.getBindingConfiguration().setMapIDs(false);
        reader.registerBeanClass("mixed", MixedUpdatersBean.class);
        bean = (MixedUpdatersBean) reader.parse(new StringReader(xml));
       
        assertEquals("Name incorrect", "Lov", bean.getName());
        assertEquals("BadName incorrect", "Hate", bean.getBadName());
        List items = bean.getItems();
        assertEquals("Wrong number of items", 2, items.size());
View Full Code Here

       
        StringReader xml = new StringReader(
            "<?xml version='1.0' encoding='UTF-8'?><deep-thought alpha='Life' gamma='42'>"
            + "The Universe And Everything</deep-thought>");
           
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(MixedContentOne.class);
        Object resultObject = reader.parse(xml);
        assertEquals("Object is MixedContentOne", true, resultObject instanceof MixedContentOne);
        MixedContentOne result = (MixedContentOne) resultObject;
        assertEquals("Property Alpha matches", "Life", result.getAlpha());
        assertEquals("Property Beta matches", "The Universe And Everything", result.getBeta());
        assertEquals("Property Gamma matches", 42, result.getGamma());
View Full Code Here

            + "<example><id>2</id><name>March Hare</name></example>"
            + "<example><id>3</id><name>Dormouse</name></example>"
            + "</example-bean>";
       
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setElementNameMapper(new HyphenatedNameMapper());
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
        reader.registerBeanClass( ExampleBean.class );
       
        StringReader in = new StringReader( xml );
        ExampleBean out = (ExampleBean) reader.parse( in );
        assertEquals("Interface read failed", bean, out);
       
    }     
View Full Code Here

                return getReferenced(context, id);
            }
           
        };
       
        BeanReader reader = new BeanReader();
        reader.getBindingConfiguration().setIdMappingStrategy(storingStrategy);
        reader.registerBeanClass(ElementsList.class);
        ElementsList elements = (ElementsList) reader.parse(new StringReader(xml));
        assertNotNull(elements);
        Element one = elements.get(0);
        assertTrue(one == alpha);
        Element two = elements.get(1);
        assertNotNull(two);
View Full Code Here

*/
public class TestCyclicRegistration extends TestCase {
   
    public void testListReferenceCycle() throws Exception {

        BeanReader reader = new BeanReader();
        reader.registerBeanClass(PlanetBean.class);
    }
View Full Code Here

        String output = outputWriter.toString();

        assertEquals(EXPECTED, output);
           
        BeanReader beanReader = new BeanReader();

        beanReader.registerMultiMapping(new InputSource(new StringReader(MAPPING)));

        StringReader xmlReader = new StringReader(output);

        container = (Container)beanReader.parse(xmlReader);

        assertTrue(container.getElement1() instanceof ElementB);
        // betwixt cannot know which type the element has
        assertNull(container.getElement2());
    }
View Full Code Here

     */
    public static final MsgBean parseMsg(String xmlMessage)
        throws Exception
    {
        MsgBean msg = null;
        BeanReader beanReader = new BeanReader();
        // Configure the reader
        beanReader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        // Register beans so that betwixt knows what the xml is
        beanReader.registerBeanClass("message", MsgBean.class);
        StringReader stringReader = new StringReader(xmlMessage);
        return  (MsgBean) beanReader.parse(stringReader);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.betwixt.io.BeanReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.