public static Account toAccount(JSONObject json) throws JSONException, ParseException {
    if (json == null) {
      return null;
    }
    Account account = new Account();
    account.setAccountId(0L);

    account.setAuthToken(ParseUtil.getRawString("access_token", json));
    String secretString = ParseUtil.getRawString("token_secret", json);
    String plainSecret = RsaUtil.decryptWithPublicKey(secretString, Constants.PUBLIC_KEY);
    account.setAuthSecret(plainSecret);

    account.setAppKey(ParseUtil.getRawString("app_key", json));
    secretString = ParseUtil.getRawString("app_secret", json);
    plainSecret = RsaUtil.decryptWithPublicKey(secretString, Constants.PUBLIC_KEY);
    account.setAppSecret(plainSecret);

    account.setAuthVersion(ParseUtil.getInt("auth_version", json));
    account.setServiceProviderNo(ParseUtil.getInt("service_provider", json));
    if (json.isNull("state")) {
      account.setState(Account.STATE_SYNCED);
    } else {
      account.setState(ParseUtil.getInt("state", json));
    }
    account.setUserId(ParseUtil.getRawString("user_id", json));
    if (!json.isNull("user")) {
      account.setUser(UserJSONConverter.toUser(json.getJSONObject("user")));
    }
    account.setCreatedAt(ParseUtil.getDate("created_at", json));
    account.setDefault(ParseUtil.getBoolean("is_default", json));
    account.setRestProxyUrl(ParseUtil.getRawString("rest_proxy_url", json));
    account.setSearchProxyUrl(ParseUtil.getRawString("search_proxy_url", json));
    account.setTokenExpiresAt(ParseUtil.getDate("token_expires_at", json));
    account.setTokenScopes(ParseUtil.getRawString("token_scopes", json));
    return account;
  }