From commons-user-return-7577-apmail-jakarta-commons-user-archive=jakarta.apache.org@jakarta.apache.org Mon May 03 16:17:26 2004 Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 445 invoked from network); 3 May 2004 16:17:26 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 3 May 2004 16:17:26 -0000 Received: (qmail 63948 invoked by uid 500); 3 May 2004 16:17:13 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 63908 invoked by uid 500); 3 May 2004 16:17:13 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 63881 invoked from network); 3 May 2004 16:17:13 -0000 Received: from unknown (HELO web11702.mail.yahoo.com) (216.136.172.68) by daedalus.apache.org with SMTP; 3 May 2004 16:17:13 -0000 Message-ID: <20040503161704.96566.qmail@web11702.mail.yahoo.com> Received: from [12.110.19.201] by web11702.mail.yahoo.com via HTTP; Mon, 03 May 2004 09:17:04 PDT Date: Mon, 3 May 2004 09:17:04 -0700 (PDT) From: b p Subject: Re: [betwixt] Problem with Maps and Arrays To: Jakarta Commons Users List In-Reply-To: <52937FE3-9B56-11D8-9556-003065DC754C@blueyonder.co.uk> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-2012951759-1083601024=:96032" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --0-2012951759-1083601024=:96032 Content-Type: text/plain; charset=us-ascii Hi Robert, Thanks a bunch. I just got the code down and ran a few initial tests with arrays and it seems to be meeting my needs. I'll get a chance to spend a little more time looking at it later this week and let you know how it goes. Thanks again, Brian robert burrell donkin wrote: hi brian i've added code supporting the test case you gave me. it's new and probably under-tested so feedback would be appreciated. add this functionality was actually quite a nice test of the refactored reading code. creating special actions to provide this functionality was clean and (relatively) easy. this was one of the major aims of the refactoring and i'm now confident that the design's about right and that the code's approaching the time when it's ready to be merged back into the main stream. - robert On 16 Apr 2004, at 22:00, b p wrote: > Hi Robert, > > I've hit a problem with Maps and arrays that I haven't been able to > resolve. I would like to write/read a Map that has an array (either > java array or collection) as the values of the map. When I write, > everything looks ok. When I read back in, I'm getting a map with no > values. If I wrap the array or collection in another bean (so the > value of the map is a bean, not an array or collection), it will work. > I can live with that if I need to, but I would prefer to have the map > values be arrays or collections directly. I haven't been able to > track down a good way to do that-- I'm hoping you'll see a relatively > easy solution I'm missing :). > > Below is a test case that shows the problem. Any suggestions? > > Thanks, > Brian > > > AddressBook.java > --------------------------------- > package org.apache.commons.betwixt.io.read; > import java.util.HashMap; > /** > * @author Brian Pugh > */ > public class AddressBook { > private HashMap addressesMap = new HashMap(); > > public HashMap getAddressBookItems() { > return addressesMap; > } > public void setAddressBookItems(HashMap map) { > this.addressesMap = map; > } > public void addAddressBookItem(String name, AddressBean[] addresses) > { > addressesMap.put(name, addresses); > } > > } > > > Test case (patch to TestMaps.java) > ---------------------------------------------------- > > Index: src/test/org/apache/commons/betwixt/io/read/TestMaps.java > =================================================================== > RCS file: > /home/cvspublic/jakarta-commons/betwixt/src/test/org/apache/commons/ > betwixt/io/read/Attic/TestMaps.java,v > retrieving revision 1.1.2.1 > diff -u -r1.1.2.1 TestMaps.java > --- src/test/org/apache/commons/betwixt/io/read/TestMaps.java 22 Feb > 2004 17:09:29 -0000 1.1.2.1 > +++ src/test/org/apache/commons/betwixt/io/read/TestMaps.java 16 Apr > 2004 20:46:55 -0000 > @@ -132,4 +132,60 @@ > > } > > + public void testMapWithArray() throws Exception { > + > + AddressBook addressBook = new AddressBook(); > + AddressBean[] johnsAddresses = new AddressBean[2]; > + johnsAddresses[0] = new AddressBean("12 here", "Chicago", > "USA", "1234"); > + johnsAddresses[1] = new AddressBean("333 there", "Los Angeles", > "USA", "99999"); > + String name = "John"; > + addressBook.addAddressBookItem(name, johnsAddresses); > + StringWriter outputWriter = new StringWriter(); > + outputWriter.write("\n"); > + BeanWriter beanWriter = new BeanWriter(outputWriter); > + beanWriter.enablePrettyPrint(); > + beanWriter.write(addressBook); > + System.out.println(outputWriter.toString()); > + String xml = "\n" + > + " \n" + > + " \n" + > + " \n" + > + " John\n" + > + " \n" + > + " \n" + > + " Chicago\n" + > + " 1234\n" + > + " USA\n" + > + " 12 here\n" + > + " \n" + > + " \n" + > + " Los Angeles\n" + > + " 99999\n" + > + " USA\n" + > + " 333 there\n" + > + " \n" + > + " \n" + > + " \n" + > + " \n" + > + " \n"; > + > + assertEquals(xml, outputWriter.toString()); > + BeanReader reader = new BeanReader(); > + reader.registerBeanClass(AddressBook.class); > + StringReader xmlReader = new > StringReader(outputWriter.toString()); > + AddressBook result = (AddressBook) reader.parse(xmlReader); > + assertNotNull("Expected to get an AddressBook!", result); > + assertNotNull("Expected AddressBook to have some address > entryitems!", result.getAddressBookItems()); > + AddressBean []resultAddresses = (AddressBean[]) > result.getAddressBookItems().get(name); > + assertNotNull("Expected to have some addresses for " + name, > resultAddresses); > + assertEquals("Got wrong city in first address for " + name, > + johnsAddresses[0].getCity(), > + resultAddresses[0].getCity()); > + assertEquals("Got wrong city in second address for " + name, > + johnsAddresses[1].getCity(), > + resultAddresses[1].getCity()); > + > + > + } > + > } > > > > > > --------------------------------- > Do you Yahoo!? > Yahoo! Tax Center - File online by April 15th --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org --------------------------------- Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs --0-2012951759-1083601024=:96032--