Serialize a {@link Writable} object into a string.

@param writable the {@link Writable} object to be serialized
@return a string serialized from the {@link Writable} object
@throws IOException if there's something wrong with the serialization
967135
public static String serializeToString(Writable writable) throws IOException {
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) {
      writable.write(dataOutputStream);
      return BaseEncoding.base64().encode(byteArrayOutputStream.toByteArray());
    }
  }
502222
public String toJson()
      throws IOException {
    StringWriter writer = new StringWriter();
    try (JsonGenerator generator = jsonFactory.createJsonGenerator(writer)
        .setCodec(objectMapper)) {
      toJsonUtf8(generator);
    }

    return writer.toString();
  }
232684
public static void write(Object value, Writer out) throws IOException {
		if(out instanceof MediaWriter) {
			// Unwrap media writer and use encoder directly
			MediaWriter mediaWriter = (MediaWriter)out;
			write(
				value,
				mediaWriter.getEncoder(),
				mediaWriter.getOut()
			);
		} else {
			if(value instanceof String) {
				// If A is a string, then the result is A.
				out.write((String)value);
			} else if(value == null) {
				// Otherwise, if A is null, then the result is "".
				// Write nothing
			} else if(value instanceof Writable) {
				Writable writable = (Writable)value;
				if(writable.isFastToString()) {
					out.write(writable.toString());
				} else {
					// Avoid intermediate String from Writable
					writable.writeTo(unwrap(out));
				}
			} else if(value instanceof Node) {
				// Otherwise, if is a DOM node, serialize the output
				try {
					// Can use thread-local or pooled transformers if performance is ever an issue
					TransformerFactory transFactory = TransformerFactory.newInstance();
					Transformer transformer = transFactory.newTransformer();
					transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
					transformer.transform(
						new DOMSource((Node)value),
						new StreamResult(unwrap(out))
					);
				} catch(TransformerException e) {
					throw new IOException(e);
				}
			} else {
				// Otherwise, if A.toString() throws an exception, then raise an error
				// Otherwise, the result is A.toString();
				out.write(value.toString());
			}
		}
	}
192760
public String serialize(boolean verbose) throws IOException {
        Serializer serializer;
        StringWriter writer = new StringWriter();

        if (verbose)
        {
            serializer = new SerializerVerbose(writer);
        }
        else
        {
            serializer = new Serializer(writer);
        }
        serializer.writeObject(this).flush();

        return writer.toString();
    }
230080
public static String encode(Object o) throws IOException {
    if (o instanceof Serializable) {
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      ObjectOutputStream objectOutputStream;
      try {
        objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(o);
        objectOutputStream.close();
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        return Base64.byteArrayToBase64(byteArray);
      } catch (IOException e) {
        e.printStackTrace();
        log.error(e);
        return null;
      }
    } else {
      throw new IOException("no serializable object");
    }
  }
446968
public static String read(Readable readable) throws IOException {
    StringBuilder builder = new StringBuilder();
    copy(readable, builder);
    return builder.toString();
  }
62936
protected String format(Throwable throwable)
    {
        String text=null;
        if(throwable!=null)
        {
            //init writer
            StringWriter writer=new StringWriter(1500);
            
            //write throwable
            throwable.printStackTrace(new PrintWriter(writer));
            
            //get text
            text=writer.toString();
        }
        
        return text;
    }
1169105
public String serialize(T object) throws IOException {
        StringWriter sw = new StringWriter();
        JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(sw);
        serialize(object, jsonGenerator, true);
        jsonGenerator.close();
        return sw.toString();
    }
609917
public static String serialize(Object obj) throws ApiException {
        try {
            if (obj != null)
                    if (obj instanceof String) {
                        // This assumes that we receive json as a string
                        return (String) obj;
                } else {
                        return JsonUtil.getJsonMapper().writeValueAsString(obj);
                }
            else
                return null;
        }
        catch (Exception e) {
            throw new ApiException(500, e.getMessage());
        }
    }
1212194
public StringBuilder toStream(final StringBuilder iOutput, Object iValue) {
    if (iValue != null) {
      if (!(iValue instanceof OSerializableStream))
        throw new OSerializationException("Cannot serialize the object since it's not implements the OSerializableStream interface");

      OSerializableStream stream = (OSerializableStream) iValue;
      iOutput.append(iValue.getClass().getName());
      iOutput.append(OStreamSerializerHelper.SEPARATOR);
      iOutput.append(OBase64Utils.encodeBytes(stream.toStream()));
    }
    return iOutput;
  }
406343
public static String readFully(Reader reader) throws IOException {
        try {
            StringWriter writer = new StringWriter();
            char[] buffer = new char[1024];
            int count;
            while ((count = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, count);
            }
            return writer.toString();
        } finally {
            reader.close();
        }
    }
543226
public static String serialize(Serializable o) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	serialize(o, baos);
	return Base64Coder.encode(baos.toByteArray());
    }
672610
@Override
    public PrintWriter getWriter() throws IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getWriter: " + this);
        }
        if (this.streamActive) {
            throw new IllegalStateException("Output stream already obtained");
        }
        if (null == this.outWriter) {
            this.outWriter = new PrintWriter(
                            new OutputStreamWriter(
                                            this.outStream, getCharacterEncoding()), false);
        }
        return this.outWriter;
    }
621882
public static Persistable persistable(final Streamable streamable) {
        return new Persistable() {

            @Override
            public int size() {
                return streamable.size();
            }

            @Override
            public void write(ByteBuffer buffer) {
                try {
                    streamable.write(new ByteBufferOutputStream(buffer));
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

            @Override
            public void read(ByteBuffer buffer) {
                try {
                    streamable.read(new ByteBufferInputStream(buffer));
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

        };
    }
768581
@JsonCreator
    public static NullableValue fromSerializable(@JsonProperty("serializable") Serializable serializable)
    {
        Type type = serializable.getType();
        Block block = serializable.getBlock();
        return new NullableValue(type, block == null ? null : Utils.blockToNativeValue(type, block));
    }
944261
public static String serialize(Value value) throws JSONException {
		StringWriter writer = new StringWriter();
		Serializer.serialize(value, writer);
		return writer.toString();
	}
610389
public static String serialize(Object[] objs)
    {
        StringBuffer buff = new StringBuffer();
        for(int i = 0; i < objs.length; i++)
        {
            if(objs[i] != null)
            {
                buff.append(objs[i].toString());
                if(i != objs.length-1)
                    buff.append(",");
            }
        }
        return buff.toString();
    }