Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 17134 invoked from network); 16 Dec 2004 05:20:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 16 Dec 2004 05:20:36 -0000 Received: (qmail 9059 invoked by uid 500); 16 Dec 2004 05:20:29 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 9040 invoked by uid 500); 16 Dec 2004 05:20:29 -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 9022 invoked by uid 99); 16 Dec 2004 05:20:29 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of crumley@gmail.com designates 64.233.170.196 as permitted sender) Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.196) by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 15 Dec 2004 21:20:01 -0800 Received: by rproxy.gmail.com with SMTP id c16so1929856rne for ; Wed, 15 Dec 2004 21:19:59 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=sNt/hJVFWXjzbQUb8n0DSJIxr86gAX6Ci9VnvCIF6AVrSkMJrXrJQHyfx+WNdiqA0pp77x1tgnG/ZpKj0s9LIBDpF7y9K7rpX/ZTBmNATkCmudSw2Bu4MWvVH5zN5LylWF809M7Qjy4uu3J3h7ZG193fGUe8y9fGqelpTsmZyWY= Received: by 10.38.161.47 with SMTP id j47mr1175688rne; Wed, 15 Dec 2004 21:19:58 -0800 (PST) Received: by 10.38.76.73 with HTTP; Wed, 15 Dec 2004 21:19:58 -0800 (PST) Message-ID: Date: Wed, 15 Dec 2004 23:19:58 -0600 From: Ryan Crumley Reply-To: Ryan Crumley To: Jakarta Commons Users List Subject: Re: ClassCastException with betwixt 0.6 In-Reply-To: <8D4499BF-4E7D-11D9-8817-003065DC754C@blueyonder.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <9D0BE4F8-4D59-11D9-B02B-003065DC754C@blueyonder.co.uk> <8D4499BF-4E7D-11D9-8817-003065DC754C@blueyonder.co.uk> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I was quite excited that the problem may have been found however I changed the code so that the configuration object is shared between the writer and reader and I am still receiving a null object back from the reader. The new code is listed below. The output when running the program is: out: null I am still at a loss why this simple example is not working. The only thing I can think of (unless someone sees a problem with the code I am using below) is that my jar versions are not correct. However I used the same jars that maven appears to use when running regression (which passes). Any ideas on where to go next? Thanks, ryan public static final void main(String args[]) throws Exception{ StringWriter out = new StringWriter(); out.write(""); BeanWriter writer = new BeanWriter(out); IntrospectionConfiguration configuration = writer.getXMLIntrospector().getConfiguration(); configuration.setAttributesForPrimitives(true); configuration.setWrapCollectionsInElement(false); 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().setConfiguration(configuration); reader.registerBeanClass(PersonBean.class); PersonBean person = (PersonBean) reader.parse(xmlReader); // send bean to system out System.out.println(person); } On Wed, 15 Dec 2004 09:41:53 +0000, robert burrell donkin wrote: > hi ryan > > i'm afraid you're going to kick yourself ;) > > On 15 Dec 2004, at 05:45, Ryan Crumley wrote: > > > > > public class TestBetwixt { > > public static final void main(String args[]) throws Exception{ > > StringWriter out = new StringWriter(); > > out.write(""); > > > > 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 > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org