Hi,
 
Can someone tell me how to use BeanSerializer / Deserializer out of the context of a message ? (ie to encode an object to XML and to parse XML for an object).
 
For the serialization I do :
 
-------------------------------------------------------------------
 
MyObject obj = new MyObject();
 
   FileWriter fout = new FileWriter("c:\\test.xml");
 
   AxisClient client = new AxisClient();
   MessageContext msgContext = new MessageContext(client);
   SerializationContextImpl context = new SerializationContextImpl(
     fout, msgContext);
   context.setPretty(true);
   context.setDoMultiRefs(false);
   context.setSendDecl(true);
 
   BeanSerializer s = (BeanSerializer) MyObject
     .getSerializer(Constants.AXIS_SAX, MyObject.class,
       MyObject.getTypeDesc().getXmlType());
   s.serialize(MyObject.getTypeDesc().getXmlType(),
     null, obj, context);
 
   fout.flush();
   fout.close();
-------------------------------------------------------------------
 
And it is working.
 
Now I don't know how to deserialize ... I tried this but it don't work :
 
-------------------------------------------------------------------
   BeanDeserializer d = (BeanDeserializer)MyObject.getDeserializer(Constants.AXIS_SAX,MyObject.class,MyObject.getTypeDesc().getXmlType());
   InputSource source = new InputSource("c:\\test.xml");
   
   SAXParser p = XMLUtils.getSAXParser();
   
   XMLReader reader = p.getXMLReader();
   
   reader.setContentHandler(d);
   reader.setDTDHandler(d);
   reader.setEntityResolver(d);
   reader.setErrorHandler(d);
   
   reader.parse(source);
   
  MyObject obj = (MyObject)d.getValue();
-------------------------------------------------------------------
 
I got an empty MyObject instance ...

I really need help.
 
Laurent Cornélis

Reply via email to