public static String serialize(Object data){
  String ret=null;
  if (data != null) {
    if (data.getClass() == String.class) {
      ret=(String)data;
    }
 else     if (data instanceof byte[]) {
      ret=new String((byte[])data);
    }
 else {
      try {
        ret=mapper.writeValueAsString(data);
      }
 catch (      JsonProcessingException e) {
        if (log.isLoggable(Level.FINEST)) {
          log.log(Level.FINEST,"Failed to serialize object into json",e);
        }
      }
    }
  }
  if (log.isLoggable(Level.FINEST)) {
    log.finest("Serialized '" + data + "' to json: "+ ret);
  }
  return ret;
}

public static String serialize ( Object data ) { String ret = null ; if ( data != null ) { if ( data . getClass ( ) == String . class ) { ret = ( String ) data ; } else if ( data instanceof byte [ ] ) { ret = new String ( ( byte [ ] ) data ) ; } else { try { ret = mapper . writeValueAsString ( data ) ; } catch ( JsonProcessingException e ) { if ( log . isLoggable ( Level . FINEST ) ) { log . log ( Level . FINEST , "Failed to serialize object into json" , e ) ; } } } } if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( "Serialized '" + data + "' to json: " + ret ) ; } return ret ; }
this method serializes the supplied object to a json document .
