code: public static Credentials createFromJson( String json )
      {
          JSONObject jsonObj = ( JSONObject ) new JSONTokener( json ).nextValue();
  
          if ( jsonObj.has( PasswordCredentials.PASSWORD ) ) {
              // Password credentials
              return PasswordCredentials.fromJson( jsonObj );
          } else {
              // OAuth2 credentials
              return OAuth2Credentials.fromJson( jsonObj );
          }
      }
docs: Create a Credential object from a JSON value. It detects automaticaly which credential is defined (OAuth or
  password)
  
  @param json The JSON to parse
  @return The credentials object