Convert a POJO into Serialized JSON form.

@param o the POJO to serialize
@param s the OutputStream to write to..
@throws IOException when there are problems creating the JSON.
198171
public static void serializeAsStream(Object o, OutputStream s) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            Map<String, Object> config = new HashMap<String, Object>();
            config.put(JsonGenerator.PRETTY_PRINTING, true);
            JsonWriterFactory writerFactory = Json.createWriterFactory(config);
            JsonWriter streamWriter = writerFactory.createWriter(s);
            streamWriter.write(builtJsonObject);
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
423871
private synchronized void writeObject(ObjectOutputStream oos) throws IOException {

        int serializable = 0;
        oos.defaultWriteObject();

        // write out the service providers
        Set<Map.Entry<Class, ServiceProvider>> providers = _serviceProviders.entrySet();
        for (Map.Entry<Class, ServiceProvider> provider : providers) {
            if (provider.getValue().isSerializable()) {
                serializable++;
            }
        }

        oos.writeInt(serializable);
        if (serializable > 0) {
            for (Map.Entry<Class, ServiceProvider> entry : providers) {
                if (entry.getValue().isSerializable()) {
                    oos.writeObject(entry.getKey());
                    oos.writeObject(entry.getValue());
                }
            }
        }

        // write out the event listeners
        serializable = 0;
        for (BeanContextServicesListener l : _bcsListeners) {
            if (l instanceof Serializable) {
                serializable++;
            }
        }

        oos.writeInt(serializable);
        if (serializable > 0) {
            for (BeanContextServicesListener l : _bcsListeners) {
                if (l instanceof Serializable) {
                    oos.writeObject(l);
                }
            }
        }
    }
87265
@SuppressWarnings("unchecked")
    public static <E> void serialize(E object, OutputStream os) throws IOException {
        mapperFor((Class<E>)object.getClass()).serialize(object, os);
    }
504753
private Serializer write(Object object) throws IOException {
        if (null == object) return writeNull();
        if (object instanceof Number) return writeNumber((Number) object);
        if (object instanceof String) return writeString((String) object);
        if (object instanceof Boolean) return writeBoolean((Boolean) object);
        if (object instanceof JSONObject) return writeObject((JSONObject) object);
        if (object instanceof JSONArray) return writeArray((JSONArray) object);

        throw new IOException("Attempting to serialize unserializable object: '" + object + "'");
    }
521619
public static String serializeAsString(Object o) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            return builtJsonObject.toString();
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
735772
@Override
    protected byte[] serialize(Object o) {
        ClassLoaderRegisteringObjectInputStream.register(o.getClass());
        return super.serialize(o);
    }
424097
protected byte[] serialize(Object o) {
    if (o == null) {
      throw new NullPointerException("Can't serialize null");
    }
    byte[] rv=null;
    ByteArrayOutputStream bos = null;
    ObjectOutputStream os = null;
    try {
      bos = new ByteArrayOutputStream();
      os = new ObjectOutputStream(bos);
      os.writeObject(o);
      os.close();
      bos.close();
      rv = bos.toByteArray();
    } catch (IOException e) {
      throw new IllegalArgumentException("Non-serializable object", e);
    } finally {
      CloseUtil.close(os);
      CloseUtil.close(bos);
    }
    return rv;
  }
1279579
private void writeObject(java.io.ObjectOutputStream s)
      throws java.io.IOException {
    s.defaultWriteObject();

    s.writeDouble(get());
  }
1263778
private void writeObject(final ObjectOutputStream s) throws IOException {
        s.defaultWriteObject();
        s.writeInt(level);
        s.writeInt(syslogEquivalent);
        s.writeUTF(levelStr);
    }
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");
    }
  }
904971
private void writeObject(java.io.ObjectOutputStream s) throws IOException  {
    s.defaultWriteObject();     // Nothing to write
    for( Object K : keySet() ) {
      final Object V = get(K);  // Do an official 'get'
      s.writeObject(K);         // Write the <TypeK,TypeV> pair
      s.writeObject(V);
    }
    s.writeObject(null);        // Sentinel to indicate end-of-data
    s.writeObject(null);
  }
548616
@GwtIncompatible("ObjectOutputStream")
  public void serialize(OutputStream objectOutputStream) throws IOException {
    new java.io.ObjectOutputStream(objectOutputStream).writeObject(this);
  }
712210
private void writeObject(java.io.ObjectOutputStream s)
        throws java.io.IOException {
        // Write out any hidden serialization magic
        s.defaultWriteObject();

        // Write out size
        s.writeInt(size);

        // Write out all elements in the proper order.
        for (Node<E> x = first; x != null; x = x.next)
            s.writeObject(x.item);
    }
89109
private void writeObject(java.io.ObjectOutputStream s)
       throws java.io.IOException {
       // Must inflate to maintain compatible serial form.
       if (this.intVal == null)
           UnsafeHolder.setIntValVolatile(this, BigInteger.valueOf(this.intCompact));
       // Could reset intVal back to null if it has to be set.
       s.defaultWriteObject();
   }
197822
private void writeObject(java.io.ObjectOutputStream s)
                    throws java.io.IOException {

        s.defaultWriteObject();

        Object[] elements = getArray();
        // Write out array length
        s.writeInt(elements.length);

        // Write out all elements in the proper order.
        for (Object element : elements)
            s.writeObject(element);
    }
188373
private void writeObject(ObjectOutputStream s) throws IOException {
        ObjectOutputStream.PutField putField = s.putFields();
        putField.put("version", version);
        putField.put("resourceAdapterKey", resourceAdapterKey);
        s.writeFields();
    }
585362
public static void writeJson(Serializable serializable, OutputStream output)
			throws IOException {
		TransportFormat.JSON.writeSerializableTo(serializable, output);
	}