code: private static Class<?> findSerializableType(Class<?> type) {
      while (type != null && type != Object.class) {
        for (Class<?> iface : type.getInterfaces()) {
          if (iface == JsonSerializable.class) {
            return type;
          }
          Class<?> serializable = findSerializableType(iface);
          if (serializable != null) {
            return serializable;
          }
        }
        type = type.getSuperclass();
      }
      return null;
    }
docs: Iterates over the class hierarchy searching for the base serializable type.