private Class getClassFromHint(Object o) throws UnmarshallException
  {
    if (o == null)
    {
      return null;
    }
    if (o instanceof JSONObject)
    {
      String className = "(unknown)";
      try
      {
        className = ((JSONObject) o).getString("javaClass");
        return Class.forName(className);
      }
      catch (Exception e)
      {
        throw new UnmarshallException("Class specified in javaClass hint not found: " + className, e);
      }
    }
    if (o instanceof JSONArray)
    {
      JSONArray arr = (JSONArray) o;
      if (arr.length() == 0)
      {
        throw new UnmarshallException("no type for empty array");
      }
      // return type of first element
      Class compClazz;
      try
      {
        compClazz = getClassFromHint(arr.get(0));
      }
      catch (JSONException e)
      {
        throw (NoSuchElementException) new NoSuchElementException(e.getMessage()).initCause(e);
      }
      try
      {
        if (compClazz.isArray())
        {
          return Class.forName("[" + compClazz.getName());
        }
        return Class.forName("[L" + compClazz.getName() + ";");
      }
      catch (ClassNotFoundException e)
      {
        throw new UnmarshallException("problem getting array type", e);
      }
    }
    return o.getClass();
  }