Re: [Simple-support] carriage return
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2012-05-03 08:50:41
|
I think this is down the the underlying parser. Simple does not parse the XML. Have you tried to use <![CDATA[ ]> blocks, use @Element(data=true).
--- On Wed, 2/5/12, Hans <fis...@ya...> wrote:
From: Hans <fis...@ya...>
Subject: [Simple-support] carriage return
To: sim...@li...
Received: Wednesday, 2 May, 2012, 11:26 PM
Hi,
The following example serializes a simple class
with one String property. This property contains
a carriage return ("\r").
After serializing the class to a String the carriage
return is preserved in the String.
After deserializing the String back to the class,
the carriage return is replaced by a line feed!
This behaviour surprised me, but after googling
around, this seems to be the normal behaviour.
So my question is what is best practice to
preserve the carriage return?
Setting the data attribute inside the annotation
of the element is not enough, the carriage
return is still replaced by a line feed.
package carriage_return;
import java.io.StringWriter;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
public class CarriageReturn {
@Root
public static class Xml {
@Element
private String content;
public Xml() {
}
public Xml(String content) {
this.content = content;
}
public String getContent() {
return content;
}
}
public static void main(String[] args) throws Exception {
Xml xml = new Xml("Hello\rSimpleXML");
Serializer serializer = new Persister();
StringWriter stringWriter = new StringWriter();
serializer.write(xml,stringWriter);
String serialzedXml = stringWriter.toString();
System.out.println(serialzedXml.contains("\r"));
xml = serializer.read(Xml.class,serialzedXml);
System.out.println(xml.getContent().contains("\r"));
}
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|