Search code examples
javagwtgwt-rpcsimple-framework

How Serialize Objects To String Using SimpleFramework


Am working with GWT application and integrated with Simple framework to parse objects into XML, I have POJO classes on client side and use the parser on server side. I need to write the serialized object to String variable instead of file cause files not allowed in GWT App engine https://groups.google.com/forum/?fromgroups=#!topic/google-web-toolkit/M7Zo3U7CKD8.

Current code I have in the server side on GWT RPC ServiceImpl

File result = new File("c:/myXMLFile.xml");
Serializer serializer = new Persister();
MyBeanToSerialize beanToSerialize = new MyBeanToSerialize("firstName","LastName");
serializer.write(beanToSerialize, result);

Solution

  • I found the solution for returning String from the XML parser by using the writer object instead of File the code is as the following:-

    String parser(){
     StringWriter writer = new StringWriter();
     Serializer serializer = new Persister();
     MyBeanToSerialize beanToSerialize = new MyBeanToSerialize("firstName","LastName");
     serializer.write(beanToSerialize, writer);
    return writer.getBuffer().toString();
    )