public static String serialize(Object toSerialize) throws Exception {
  Class<?> xstreamClass;
  java.lang.reflect.Constructor<?> constructor;
  Object xstream;
  Class<?>[] serializeArgsClasses=new Class[1];
  Object[] serializeArgs=new Object[1];
  java.lang.reflect.Method methodSerialize;
  String result;
  xstreamClass=Class.forName("com.thoughtworks.xstream.XStream");
  constructor=xstreamClass.getConstructor();
  xstream=constructor.newInstance();
  serializeArgsClasses[0]=Object.class;
  serializeArgs[0]=toSerialize;
  methodSerialize=xstreamClass.getMethod("toXML",serializeArgsClasses);
  try {
    result=(String)methodSerialize.invoke(xstream,serializeArgs);
  }
 catch (  Exception ex) {
    result=null;
  }
  return result;
}

public static String serialize ( Object toSerialize ) throws Exception { Class < ? > xstreamClass ; java . lang . reflect . Constructor < ? > constructor ; Object xstream ; Class < ? > [ ] serializeArgsClasses = new Class [ 1 ] ; Object [ ] serializeArgs = new Object [ 1 ] ; java . lang . reflect . Method methodSerialize ; String result ; xstreamClass = Class . forName ( "com.thoughtworks.xstream.XStream" ) ; constructor = xstreamClass . getConstructor ( ) ; xstream = constructor . newInstance ( ) ; serializeArgsClasses [ 0 ] = Object . class ; serializeArgs [ 0 ] = toSerialize ; methodSerialize = xstreamClass . getMethod ( "toXML" , serializeArgsClasses ) ; try { result = ( String ) methodSerialize . invoke ( xstream , serializeArgs ) ; } catch ( Exception ex ) { result = null ; } return result ; }
serializes the supplied object xml
