Converts input object to byte array.
@param object input object
@return raw bytes
@throws JsonProcessingException
@throws IllegalAccessException
19105
@Deprecated
	public byte [] writeObject(Object object) throws JsonProcessingException, IllegalAccessException {
		try {
			return writeDocument(new JSONAPIDocument<>(object));
		} catch (DocumentSerializationException e) {
			throw new RuntimeException(e);
		}
	}
90539
public static byte[] serialize(Object object) {
		
		byte[] result = null;
		
		if (object == null) {
			return new byte[0];
		}
		try {
			ByteArrayOutputStream byteStream = new ByteArrayOutputStream(128);
			try  {
				if (!(object instanceof Serializable)) {
					throw new IllegalArgumentException(SerializeUtils.class.getSimpleName() + " requires a Serializable payload " +
							"but received an object of type [" + object.getClass().getName() + "]");
				}
				ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteStream);
				objectOutputStream.writeObject(object);
				objectOutputStream.flush();
				result =  byteStream.toByteArray();
			}
			catch (Throwable ex) {
				throw new Exception("Failed to serialize", ex);
			}
		} catch (Exception ex) {
			logger.error("Failed to serialize",ex);
		}
		return result;
	}
962561
@Override
   protected Object convert(Object instance) {
      try {
         return ProtobufUtil.toWrappedByteArray(serializationContext, instance);
      } catch (IOException e) {
         throw new CacheException(e);
      }
   }
726944
public static byte[] serialize(final Object obj) {
        if (obj == null) {
            return null;
        }
        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            final ObjectOutputStream out = new ObjectOutputStream(baos);
            out.writeObject(obj);
            return baos.toByteArray();
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
1355172
@Override
    public byte[] toBytes(Object object)
    {
        Short s = null;
        if (object != null)
        {

            if (object.getClass().isAssignableFrom(String.class))
            {
                s = Short.valueOf(object.toString());
            }
            else
            {
                s = (Short) object;
            }
            return new byte[] { (byte) ((s >> 8) & 0xff), (byte) ((s >> 0) & 0xff), };
        }
        return null;
    }
884574
public static String serialize(Object object) {
	if (object == null) return "[null]";
	try {
	    return new ScriptConverter().serialize(object);
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return object.toString();
	}
    }
102019
protected byte[] jsonSerialize(Object o) {
        byte[] res = null;
        try {
            res = JsonUtils.toJson(o).getBytes("utf-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("JsonSerialize object fail ", e);
        }
        return res;
    }
1261585
public static byte[] serialize(Object obj) {
        try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos)) {
            oos.writeObject(obj);
            return bos.toByteArray();
        } 
        catch (IOException ex) {
            throw new UncheckedIOException(ex);
        }
    }
821345
private static byte[] transform(final InputStream body) throws IOException {
        final ByteArrayOutputStream res = new ByteArrayOutputStream();
        try (JsonReader rdr = Json.createReader(body)) {
            final JsonObject obj = rdr.readObject();
            try (JsonWriter wrt = Json.createWriterFactory(
                Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)
                )
                .createWriter(res)
            ) {
                wrt.writeObject(obj);
            }
        } catch (final JsonException ex) {
            throw new IOException(ex);
        }
        return res.toByteArray();
    }
228848
protected <T> byte[] encode(T object) {
    return object != null ? userSerializer.encode(object) : null;
  }
329968
public static byte[] serialize(FastSerializable object) throws IOException {
        FastSerializer out = new FastSerializer();
        object.writeExternal(out);
        return out.getBBContainer().b().array();
    }
928909
private static byte[] convertFieldToByte(ObjectMetaData objectMap, Object object, Charset charset)
            throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        List<FieldMetaData> mappingFields = objectMap.getFieldList();
        // 获取报文长度 (固定长度+动态长度)
        int size = objectMap.getFieldsSendTotalByteSize(object, charset);
        byte[] result = new byte[size];
        int offsize = 0;
        for (int i = 0; i < mappingFields.size(); i++) {
            FieldMetaData field = mappingFields.get(i);
            byte[] fieldByte = field.toByte(object, charset);
            if (null != fieldByte) {
                System.arraycopy(fieldByte, 0, result, offsize, fieldByte.length);
                offsize += fieldByte.length;
            }
        }
        return result;
    }
232746
@SuppressWarnings("unchecked")
   public static <T> T unwrap(Object object)
   {
      T result = (T) object;

      if (object != null)
      {
         while (isForgeProxy(result))
         {
            try
            {
               Method method = result.getClass().getMethod("getDelegate");
               method.setAccessible(true);
               result = (T) method.invoke(result);
            }
            catch (Exception e)
            {
               break;
            }
         }

         if (result == null)
            result = (T) object;
      }
      return result;
   }
1198357
private static byte[] toBytes(Object input) {
        if (input instanceof byte[]) {
            return (byte[]) input;
        } else if (input instanceof String) {
            String inputString = (String) input;
            return inputString.getBytes();
        } else if (input instanceof Long) {
            Long inputLong = (Long) input;
            return (inputLong == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputLong));
        } else if (input instanceof Integer) {
            Integer inputInt = (Integer) input;
            return (inputInt == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputInt));
        } else if (input instanceof BigInteger) {
            BigInteger inputBigInt = (BigInteger) input;
            return (inputBigInt.equals(BigInteger.ZERO)) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(inputBigInt);
        }
        throw new RuntimeException("Unsupported type: Only accepting String, Integer and BigInteger for now");
    }
1144861
public String serialize(Object object) {
		ObjectOutputStream oos = null;
		ByteArrayOutputStream bos = null;
		try {
			bos = new ByteArrayOutputStream();
			oos = new ObjectOutputStream(bos);
			oos.writeObject(object);
			return new String(Base64.encodeBase64(bos.toByteArray()));
		} catch (IOException e) {
			LOGGER.error("Can't serialize data on Base 64", e);
			throw new IllegalArgumentException(e);
		} catch (Exception e) {
			LOGGER.error("Can't serialize data on Base 64", e);
			throw new IllegalArgumentException(e);
		} finally {
			try {
				if (bos != null) {
					bos.close();
				}
			} catch (Exception e) {
				LOGGER.error("Can't close ObjetInputStream used for serialize data on Base 64", e);
			}
		}
	}
1031963
public static String toPrettyJson(Object object){
		try {			
			return getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
579952
public static String toJson(Object object) {
        Objects.requireNonNull(object, Required.OBJECT.toString());
        
        String json = null;
        try {
            json = mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            LOG.error("Failed to convert object to json",  e);
        }
        
        return json;
    }