SimpleXML serializer just sends the first line

I have a problem sending an xml file between Android and a servlet using POST. I use ( Simple XML ) for serialization.

My servlet makes an answer on Android:

Serializer serial = new Persister();
OutputStream o = response.getOutputStream();

MyXML myXML = new MyXML();
myXML.setMyElement("test");
serial.write(myXML, o);

It should send my xml directly to a client like this,

<MyXML>
  <MyElement>test</MyElement>
</MyXML> 

But it sends only the first line. Then, on the Android side, this exception appears because it cannot 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 donโ€™t understand why it only serializes the first line when I do it with OutputStream, because it works when I save files without sending,

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 this way, not with bytes, to avoid setting the length of the response content.

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;           
       }
}

Thank.

+3
1

"a" . POJO:

@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;           
       }
}

, .

+1

All Articles