Title: Betwixt Configuration to process XML-formatted values

I am having trouble marshalling a JavaBean with one of its attribute values set to a text which is an XML  string.  I have a JavaBean Foo.java, and I use Commons Betwixt to marshall JavaBean in XML. Here is what  I am doing:

// JavaBean
public class Foo
{
  private String val = null;

  public void setVal (String val)
  {
    this.val = val;
  }

  public String getVal()
  {
    return this.val;
  }
}

// Test program
import java.io.StringWriter;
import org.apache.commons.betwixt.io.BeanWriter;

public class test
{
  public static void main (String [] args)
  {
    test t = new test();
    t.doStuff();
  }
 
  public void doStuff()
  {
    Foo bean = new Foo();
    bean.setVal("<![CDATA[<error>Some Error</error>]]");

    StringWriter outputWriter = new StringWriter();
    BeanWriter beanWriter = new BeanWriter(outputWriter);
    beanWriter.getXMLIntrospector().setAttributesForPrimitives(false);
    beanWriter.setWriteIDs(false);
    beanWriter.enablePrettyPrint();
    beanWriter.write("foo", bean);
    System.out.println("XML:  "+ outputWriter.toString());
  }
 
The XML I am getting looks the following:

<foo>
  <val>
    &lt;![CDATA[&lt;error&gt;Some Error&lt;/error&gt;]]&gt;
  </val>
</foo>

when I would need it to be:

<foo>
  <val>
    <![CDATA[<error>Some Error</error>]]
  </val>
</foo>

I have no issues marshalling this Bean using Castor. Any help on how to get Betwixt to produce the desired  XML string is welcome.

Thanks,
Max

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to