Example #1
0
  /**
   * Serialize an object of the given Type T into a String.
   *
   * @param object the {@link Object} to serialize
   * @return serialized {@link String} of the object or null if there is no suitable serializer
   *     registered
   */
  @SuppressWarnings("unchecked")
  public static <T> String serialize(T object) {
    Serializer<T> ser = (Serializer<T>) instance.serializers.get(object.getClass());

    if (ser != null) {
      return ser.serialize(object);
    }
    return null;
  }
Example #2
0
  /**
   * Accepts a String with data and the type it should deserialize into.
   *
   * @param data the data to have deserialized
   * @param shell object of given type or null if there is no suitable serializer registered
   * @return deserialized data
   */
  @SuppressWarnings("unchecked")
  public static <T> T deserialize(String data, Class<T> shell) {
    Serializer<T> ser = (Serializer<T>) instance.serializers.get(shell);

    if (ser != null) {
      try {
        return ser.deserialize(data);
      } catch (CanaryDeserializeException e) {
        log.error("Deserialization failure.", e);
      }
    }
    return null;
  }