Search in sources :

Example 76 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project Saiy-PS by brandall76.

the class CustomCommandHelper method deleteCommandsForPackage.

/**
 * Delete all of the {@link CustomCommand} for the given package names.
 *
 * @param ctx          the application context
 * @param packageNames the package names for which commands should be deleted
 */
public static void deleteCommandsForPackage(@NonNull final Context ctx, @NonNull final ArrayList<String> packageNames) {
    synchronized (lock) {
        final long then = System.nanoTime();
        final DBCustomCommand dbCustomCommand = new DBCustomCommand(ctx);
        if (dbCustomCommand.databaseExists()) {
            final ArrayList<CustomCommandContainer> customCommandContainerArray = dbCustomCommand.getKeyphrases();
            final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
            final ArrayList<Long> rowIds = new ArrayList<>();
            CustomCommand customCommand;
            for (final CustomCommandContainer container : customCommandContainerArray) {
                Intent remoteIntent = null;
                try {
                    customCommand = gson.fromJson(container.getSerialised(), CustomCommand.class);
                    if (customCommand.getCustomAction() == CUSTOM_INTENT_SERVICE) {
                        remoteIntent = Intent.parseUri(customCommand.getIntent(), 0);
                    }
                } catch (final URISyntaxException e) {
                    if (DEBUG) {
                        MyLog.w(CLS_NAME, "remoteIntent.parseUri: URISyntaxException");
                        e.printStackTrace();
                    }
                } catch (final JsonSyntaxException e) {
                    if (DEBUG) {
                        MyLog.w(CLS_NAME, "gson.fromJson: JsonSyntaxException");
                        e.printStackTrace();
                    }
                }
                if (remoteIntent != null && packageNames.contains(remoteIntent.getPackage())) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "adding " + remoteIntent.getPackage() + " to be deleted");
                    }
                    rowIds.add(container.getRowId());
                }
            }
            if (!rowIds.isEmpty()) {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "deleting " + rowIds.size() + " commands");
                }
                dbCustomCommand.deleteRows(rowIds);
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "no commands for packages");
                }
            }
        } else {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "databaseExists: false");
            }
        }
        if (DEBUG) {
            MyLog.getElapsed("deleteCommandsForPackage", then);
        }
    }
}
Also used : DBCustomCommand(ai.saiy.android.database.DBCustomCommand) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Intent(android.content.Intent) URISyntaxException(java.net.URISyntaxException) DBCustomCommand(ai.saiy.android.database.DBCustomCommand) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 77 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project ttdj by soonphe.

the class BCMockPayActivity method initButtonBehaviors.

void initButtonBehaviors() {
    cancelView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (BCPay.payCallback != null) {
                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_CANCEL, BCPayResult.APP_PAY_CANCEL_CODE, BCPayResult.RESULT_CANCEL, BCPayResult.RESULT_CANCEL, BCCache.getInstance().billID));
            } else {
                Log.e(TAG, "Callback should not be null");
            }
            finish();
        }
    });
    payButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadingDialog.show();
            // 发送模拟的异步通知
            BCCache.executorService.execute(new Runnable() {

                @Override
                public void run() {
                    String notifyUrl = BCHttpClientUtil.getNotifyPayResultSandboxUrl() + "/" + BCCache.getInstance().billID;
                    BCHttpClientUtil.Response response = BCHttpClientUtil.httpGet(notifyUrl);
                    loadingDialog.dismiss();
                    if (response.code == 200 || (response.code >= 400 && response.code < 500)) {
                        String ret = response.content;
                        // 反序列化json
                        Gson gson = new Gson();
                        Type type = new TypeToken<Map<String, Object>>() {
                        }.getType();
                        Map<String, Object> responseMap;
                        try {
                            responseMap = gson.fromJson(ret, type);
                        } catch (JsonSyntaxException ex) {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE, BCPayResult.FAIL_EXCEPTION, "JsonSyntaxException or Network Error:" + response.code + " # " + response.content));
                            } else {
                                Log.e(TAG, "Callback should not be null");
                            }
                            return;
                        }
                        // 判断后台返回结果
                        Integer resultCode = ((Double) responseMap.get("result_code")).intValue();
                        if (resultCode == 0) {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_SUCCESS, BCPayResult.APP_PAY_SUCC_CODE, BCPayResult.RESULT_SUCCESS, BCPayResult.RESULT_SUCCESS, BCCache.getInstance().billID));
                            } else {
                                Log.e(TAG, "Callback should not be null");
                            }
                        } else {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, resultCode, String.valueOf(responseMap.get("result_msg")), String.valueOf(responseMap.get("err_detail"))));
                            } else {
                                Log.e(TAG, "Callback should not be null");
                            }
                        }
                    } else {
                        if (BCPay.payCallback != null) {
                            BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, BCPayResult.APP_INTERNAL_NETWORK_ERR_CODE, BCPayResult.FAIL_NETWORK_ISSUE, "Network Error:" + response.code + " # " + response.content));
                        } else {
                            Log.e(TAG, "Callback should not be null");
                        }
                    }
                    finish();
                }
            });
        }
    });
}
Also used : Gson(com.google.gson.Gson) BCPayResult(cn.beecloud.entity.BCPayResult) TextView(android.widget.TextView) View(android.view.View) Type(java.lang.reflect.Type) JsonSyntaxException(com.google.gson.JsonSyntaxException) Map(java.util.Map)

Example 78 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project ttdj by soonphe.

the class BCRevertStatus method transJsonToObject.

/**
 * 将json串转化为BCRevertStatus实例
 * @param jsonStr   json串
 * @return          BCRevertStatus实例
 */
public static BCRevertStatus transJsonToObject(String jsonStr) {
    // 反序列化json
    Gson res = new Gson();
    BCRevertStatus status;
    try {
        status = res.fromJson(jsonStr, new TypeToken<BCRevertStatus>() {
        }.getType());
    } catch (JsonSyntaxException ex) {
        status = new BCRevertStatus(BCRestfulCommonResult.APP_INNER_FAIL_NUM, BCRestfulCommonResult.APP_INNER_FAIL, "JsonSyntaxException or Network Error:" + jsonStr);
    }
    return status;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson)

Example 79 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class CapeConfigManager method parse.

public CapeConfig parse(InputStream is) {
    if (is == null)
        throw new NullPointerException("Can not parse a null input stream!");
    CapeConfig instance = new CapeConfig();
    InputStreamReader isr = new InputStreamReader(is);
    try {
        Map<String, Object> entries = new Gson().fromJson(isr, Map.class);
        for (Map.Entry<String, Object> entry : entries.entrySet()) {
            final String nodeName = entry.getKey();
            final Object obj = entry.getValue();
            if (obj instanceof Map)
                parseGroup(instance, nodeName, (Map) obj);
            else if (obj instanceof String)
                parseUser(instance, nodeName, (String) obj);
        }
    } catch (JsonSyntaxException e) {
        DevCapes.logger.error("CapeConfig could not be parsed because:");
        e.printStackTrace();
    }
    return instance;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) HashBiMap(com.google.common.collect.HashBiMap) Map(java.util.Map)

Example 80 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project LauncherV3 by TechnicPack.

the class SettingsFactory method tryGetSettings.

private static TechnicSettings tryGetSettings(File rootDir) {
    if (!rootDir.exists())
        return null;
    File settingsFile = new File(rootDir, "settings.json");
    if (settingsFile == null || !settingsFile.exists())
        return null;
    try {
        String json = FileUtils.readFileToString(settingsFile, Charset.forName("UTF-8"));
        TechnicSettings settings = Utils.getGson().fromJson(json, TechnicSettings.class);
        if (settings != null)
            settings.setFilePath(settingsFile);
        return settings;
    } catch (JsonSyntaxException e) {
        Utils.getLogger().log(Level.WARNING, "Unable to load version from " + settingsFile);
        return null;
    } catch (IOException e) {
        Utils.getLogger().log(Level.WARNING, "Unable to load version from " + settingsFile);
        return null;
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) File(java.io.File)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)379 Gson (com.google.gson.Gson)169 IOException (java.io.IOException)83 HashMap (java.util.HashMap)68 JsonElement (com.google.gson.JsonElement)62 JsonObject (com.google.gson.JsonObject)58 ArrayList (java.util.ArrayList)46 JsonParser (com.google.gson.JsonParser)42 GsonBuilder (com.google.gson.GsonBuilder)38 Cursor (android.database.Cursor)33 InputStreamReader (java.io.InputStreamReader)30 Map (java.util.Map)30 BadRequestException (co.cask.cdap.common.BadRequestException)28 JsonArray (com.google.gson.JsonArray)28 Path (javax.ws.rs.Path)28 Reader (java.io.Reader)26 Type (java.lang.reflect.Type)23 JsonIOException (com.google.gson.JsonIOException)21 FileReader (java.io.FileReader)21 File (java.io.File)19