commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nechiporenko, Maxim" <Maxim.Nechipore...@FMR.COM>
Subject Betwixt appears to escape special characters
Date Mon, 22 Mar 2004 18:41:25 GMT
I am having trouble marshalling a JavaBean with one of its attribute
values set to a text which is an XML  string. It looks like Betwixt
escapes special characters coverting them to ASCII. 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


Mime
View raw message