Serializer SimpleXML just send first line
I have a problem trying to send a file xml between Android and a servlet with POST. I'm using (Simple XML) for the serializing.
My servlet do the response to Android:
Serializer serial = new Persister();
OutputStream o = response.getOutputStream();
MyXML myXML = new MyXML();
myXML.setMyElement("test");
serial.write(myXML, o);
It's supposed to send my xml directly to the client like this,
<MyXML>
<MyElement>test</MyElement>
</MyXML>
But it only sends the fir开发者_StackOverflowst line . Then, on the Android side gets this exception because it can't get the second line with the Element.
WARN/System.err(490): org.simpleframework.xml.core.ElementException: Element 'MyElement' does not have a match in class java.lang.Class at line -1
I can't understand why it only serialize the first line when i'm doing it with OutputStream because it works when i'm saving on files without sending it,
Serializer serial = new Persister();
File file = new File("MyPath");
MyXML myXML = new MyXML();
myXML.setMyElement("test");
serial.write(myXML, file);
I need to do it like that and not with bytes, just to avoid to set the response content length.
Many thanks,
EDIT: Adding MyXML.class
There is MyXML.class,
package part.myApp;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
@Root(name="MyXML")
public class MyXML{
@Element(name="MyElement")
private String a;
public void setMyElement(String a){
this.a=a;
}
public String getMyElement() {
return a;
}
}
Thanks.
Private access on 'a' might be a problem. Use the POJO options:
@Root(name="MyXML")
public class MyXML{
private String a;
@Element(name="MyElement")
public void setMyElement(String a){
this.a=a;
}
@Element(name="MyElement")
public String getMyElement() {
return a;
}
}
Let me know if that works for you.
精彩评论