You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by David Gough <Da...@leeds.orange.co.uk> on 2005/11/25 10:13:05 UTC

Betwixt - Strings set to null strings when reading a Collection of strings

I have been trying to get Betwixt to read/write my java classes and have
run into a problem with read Collections of Strings.

 

Included is a very simple test to write out a collection of strings to a
file and read them back. The output is fine, but when I read the Strings
back, they are set to "null". Am I doing something wrong. I have scoured
the docs and can't see a problem.

 

Here's the class I am I am testing with

 

import java.util.ArrayList;

import java.util.List;

 

 

public class TestStrings {

    

    List testStrings = new ArrayList();

    

    

    /** Creates a new instance of TestStrings */

    public TestStrings() {

    }

    

    public List getTestStrings() {

        return testStrings;

    }

    

    public void addTestString(String testString) {

        System.out.println("Adding testString: " + testString);

        testStrings.add(testString);

    }

    

}

 

And the teststrings.betwixt file:

 

<?xml version="1.0" encoding="UTF-8" ?>

<info>

    <element name="test">

 

        <element name="teststrings">

            <element name="teststring" property="testStrings"
updater="addTestString"/>

        </element>

 

    </element>

</info>

 

 

 

Some example code to read/write

 

public void testStringsWriteRead() throws Exception {

        System.out.println("testStringsWriteRead");

        String outFile = "teststrings.xml";

        FileOutputStream fos = new FileOutputStream(outFile);

        TestStrings testStrings = new TestStrings();

        testStrings.addTestString("test1");

        testStrings.addTestString("test2");

        BeanWriter writer = new BeanWriter(fos);

        writer.writeXmlDeclaration("<?xml version=\"1.0\" ?>");

        writer.setWriteIDs(false);

        writer.enablePrettyPrint();        

        writer.write(testStrings);     

        

       FileInputStream fis = new FileInputStream(outFile);

        BeanReader reader = new BeanReader();

        setReaderProperties(reader);

        reader.registerBeanClass(new
InputSource(TestStrings.class.getResourceAsStream("teststrings.betwixt")
), TestStrings.class);

        TestStrings testStrings2 = (TestStrings)reader.parse(new
InputSource(outFile));

        

        // Write out again to console

        writer = new BeanWriter();

        writer.getXMLIntrospector().setAttributesForPrimitives(false);

        writer.setWriteIDs(false);

        writer.enablePrettyPrint();        

        writer.write(testStrings2);                   

    }      

    

 

output - teststring.xml:

 

<?xml version="1.0" ?>

  <test>

    <teststrings>

      <teststring>test1</teststring>

      <teststring>test2</teststring>

    </teststrings>

  </test>

 

testStrings2 does not have any strrings in it's list when it is read
from the example output above.

 

What am I doing wrong?

 

Regards,

 

Dave Gough



Important.
Confidentiality: This communication is intended for the above-named person and may be confidential and/or legally privileged. Any opinions expressed in this communication are not necessarily those of the company. If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately.

Monitoring/Viruses

Orange may monitor all incoming and outgoing emails in line with current legislation. Although we have taken steps to ensure that this email and attachments are free from any virus, we advise that in keeping with good computing practice the recipient should ensure they are actually virus free.

Orange PCS Limited is a subsidiary of Orange SA and is registered in England No 2178917, with its address at St James Court, Great Park Road, Almondsbury Park, Bradley Stoke, Bristol BS32 4QJ.

Re: Betwixt - Strings set to null strings when reading a Collection of strings

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Fri, 2005-11-25 at 09:13 +0000, David Gough wrote:
> I have been trying to get Betwixt to read/write my java classes and have
> run into a problem with read Collections of Strings.

hi david

(sorry for the late response: my ISP's had major major email issues for
the last or so)

this is a bug. i've committed a fix. please try again using a recent
nightly or a new version rolled from trunk in svn.

- robert


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org