You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by acec acec <to...@yahoo.ca> on 2009/01/20 15:43:26 UTC
Betwixt output a List
I defined the following two classes and used the following code to get XML string.
Here is the one result:
<InvoiceMod>
<InvoiceLineModList>
<InvoiceLineMod>
<Quantity>11</Quantity>
<TxnLineID>aa</TxnLineID>
</InvoiceLineMod>
</InvoiceLineModList>
<TxnID>1-1231787678</TxnID>
</InvoiceMod>
For List attribute, I do not want to have <InvoiceLineModList>. How can I define InvoiceMod.betwixt?
Thanks a lot.
Arden
=================================================================
StringWriter outputWriter = new StringWriter();
// Betwixt just writes out the bean as a fragment
// So if we want well-formed xml, we need to add the prolog
outputWriter.write("<?xml version=\"1.0\"?>");
// Create a BeanWriter which writes to our prepared stream
BeanWriter beanWriter = new BeanWriter(outputWriter);
// Configure betwixt
beanWriter.enablePrettyPrint();
beanWriter.setWriteEmptyElements(false);
beanWriter.getBindingConfiguration().setMapIDs(false);
beanWriter.getXMLIntrospector().getConfiguration().setElementNameMapper(new CapitalizeNameMapper());
beanWriter.write(qbXmlBean);
String xmlString = outputWriter.toString();
=================================================================
public class InvoiceMod {
private String txnID;
private List<InvoiceLineMod> invoiceLineModList = new ArrayList<InvoiceLineMod>();
public String getTxnID() {
return txnID;
}
public void setTxnID(String txnID) {
this.txnID = txnID;
}
public List<InvoiceLineMod> getInvoiceLineModList() {
return invoiceLineModList;
}
public void addInvoiceLineMod(InvoiceLineMod invoiceLineMod) {
invoiceLineModList.add(invoiceLineMod);
}
}
public class InvoiceLineMod {
private String txnLineID;
private Integer quantity;
public String getTxnLineID() {
return txnLineID;
}
public void setTxnLineID(String txnLineID) {
this.txnLineID = txnLineID;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
}
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Betwixt output a List
Posted by acec acec <to...@yahoo.ca>.
Finally, I figured it out.
Here is the answer:
<?xml version="1.0" encoding="UTF-8" ?>
<info>
<element name="InvoiceMod">
<element name='InvoiceLineMod' property='invoiceLineModList'/>
<addDefaults/>
</element>
</info>
Thanks.
Arden
--- On Tue, 1/20/09, acec acec <to...@yahoo.ca> wrote:
> From: acec acec <to...@yahoo.ca>
> Subject: Betwixt output a List
> To: user@commons.apache.org
> Received: Tuesday, January 20, 2009, 9:43 AM
> I defined the following two classes and used the following
> code to get XML string.
>
> Here is the one result:
> <InvoiceMod>
> <InvoiceLineModList>
> <InvoiceLineMod>
> <Quantity>11</Quantity>
> <TxnLineID>aa</TxnLineID>
> </InvoiceLineMod>
> </InvoiceLineModList>
> <TxnID>1-1231787678</TxnID>
> </InvoiceMod>
>
> For List attribute, I do not want to have
> <InvoiceLineModList>. How can I define
> InvoiceMod.betwixt?
>
> Thanks a lot.
> Arden
>
>
> =================================================================
>
> StringWriter outputWriter = new StringWriter();
>
> // Betwixt just writes out the bean as a fragment
> // So if we want well-formed xml, we need to add the
> prolog
> outputWriter.write("<?xml
> version=\"1.0\"?>");
> // Create a BeanWriter which writes to our prepared
> stream
> BeanWriter beanWriter = new BeanWriter(outputWriter);
>
> // Configure betwixt
> beanWriter.enablePrettyPrint();
> beanWriter.setWriteEmptyElements(false);
> beanWriter.getBindingConfiguration().setMapIDs(false);
> beanWriter.getXMLIntrospector().getConfiguration().setElementNameMapper(new
> CapitalizeNameMapper());
>
>
> beanWriter.write(qbXmlBean);
>
> String xmlString = outputWriter.toString();
>
> =================================================================
> public class InvoiceMod {
> private String txnID;
>
> private List<InvoiceLineMod> invoiceLineModList =
> new ArrayList<InvoiceLineMod>();
>
> public String getTxnID() {
> return txnID;
> }
>
> public void setTxnID(String txnID) {
> this.txnID = txnID;
> }
>
> public List<InvoiceLineMod> getInvoiceLineModList()
> {
> return invoiceLineModList;
> }
>
> public void addInvoiceLineMod(InvoiceLineMod
> invoiceLineMod) {
> invoiceLineModList.add(invoiceLineMod);
> }
>
> }
>
> public class InvoiceLineMod {
> private String txnLineID;
> private Integer quantity;
>
> public String getTxnLineID() {
> return txnLineID;
> }
>
> public void setTxnLineID(String txnLineID) {
> this.txnLineID = txnLineID;
> }
>
> public Integer getQuantity() {
> return quantity;
> }
>
> public void setQuantity(Integer quantity) {
> this.quantity = quantity;
> }
> }
>
>
>
> __________________________________________________________________
> Looking for the perfect gift? Give the gift of Flickr!
>
> http://www.flickr.com/gift/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail:
> user-help@commons.apache.org
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org