code: 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);
                      }
                  }
              }
          }
docs: This method serializes the supplied object to a JSON document.
  
  @param data The object
  @return The JSON representation