commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Erdely" <mjerd...@gmail.com>
Subject [betwixt] How do I control the mapping of a member class, Java --> XML?
Date Mon, 21 Aug 2006 22:04:17 GMT
My JavaBean has shippingAddress (of type Address) as a member of
Customer along with a few primitives.

My configuration file properly renames the shippingAddress element
with the proper namespace. However, for the Address object primitives,
my the configuration file gets ignored so the elements have the wrong
names and no namespace.

Any ideas? I am hoping I am just missing something simple.

I am using Betwixt 0.7.

-Michael


Snippet of XML
________________________________________________________________________
<bt1:Customer name="Mr Smith"
xmlns:bt1="http://www.example.com/customer/2006-06-01/">
    <bt1:ShippingAddress>
      <addressLine1>123 Main St</addressLine1>
      <city>Anytown</city>
	

Customer.betwixt snippet
________________________________________________________________________
<?xml version='1.0' encoding='UTF-8' ?>
<info>
	<element name='Customer' uri='http://www.example.com/customer/2006-06-01/'>
		<attribute name='name' property='name'/>
		<element name='ShippingAddress' property='shippingAddress'
uri='http://www.example.com/customer/2006-06-01/'>
			<element name='AddressLine1' property='addressLine1'
uri='http://www.example.com/customer/2006-06-01/'/>
			<element name='City' property='city'
uri='http://www.example.com/customer/2006-06-01/'/>

			
Java Code
________________________________________________________________________
Customer customer = new Customer ();
customer.setName("Mr Smith");

Address address = new Address ();
address.setAddressLine1("123 Main St");
address.setCity("Anytown");

customer.setShippingAddress(address);

StringWriter outputWriter = new StringWriter();
BeanWriter beanWriter = new BeanWriter(outputWriter);

beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
beanWriter.getBindingConfiguration().setMapIDs(false);
beanWriter.setWriteEmptyElements(false);
beanWriter.enablePrettyPrint();

beanWriter.write(customer);

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