Java Code Examples for org.codehaus.jettison.json.JSONObject#remove()

The following examples show how to use org.codehaus.jettison.json.JSONObject#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonHelper.java    From OSTMap with Apache License 2.0 6 votes vote down vote up
public static String generateCoordinates(String json) {
    try {
        JSONObject obj = new JSONObject(json);
        Double[] longLat = Extractor.extractLocation(obj);

        if (obj.has(KEY_COORDINATES) && obj.isNull(KEY_COORDINATES)) {
            //coordinates is empty
            JSONArray longLatArr = new JSONArray();
            if (longLat != null && longLat[0] != null && longLat[1] != null) {
                longLatArr.put(longLat[0]);
                longLatArr.put(longLat[1]);
                JSONObject coordinates1 = new JSONObject().put(KEY_COORDINATES, longLatArr);
                obj.put(KEY_COORDINATES, coordinates1);
            }
        }
        if (obj.has(KEY_PLACE)) {
            //ccordinates is set, remove place
            obj.remove(KEY_PLACE);
        }
        return obj.toString();
    } catch (JSONException e) {
        log.error("no correct JSON string:" + json);

        return null;
    }
}
 
Example 2
Source File: ApexCli.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  String[] tmpArgs = new String[args.length - 2];
  System.arraycopy(args, 2, tmpArgs, 0, args.length - 2);
  GetAppPackageInfoCommandLineInfo commandLineInfo = getGetAppPackageInfoCommandLineInfo(tmpArgs);
  try (AppPackage ap = newAppPackageInstance(new URI(args[1]), true)) {
    JSONSerializationProvider jomp = new JSONSerializationProvider();
    jomp.addSerializer(PropertyInfo.class,
        new AppPackage.PropertyInfoSerializer(commandLineInfo.provideDescription));
    JSONObject apInfo = new JSONObject(jomp.getContext(null).writeValueAsString(ap));
    apInfo.remove("name");
    printJson(apInfo);
  }
}
 
Example 3
Source File: LivyRestExecutor.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void livyLog(JSONObject logInfo, Logger logger) {
    for (String log: getLogs(logInfo)) {
        logger.log(log);
    }
    logInfo.remove("log");
    logger.log(logInfo.toString());
}
 
Example 4
Source File: ApexCli.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  String[] tmpArgs = new String[args.length - 2];
  System.arraycopy(args, 2, tmpArgs, 0, args.length - 2);
  GetAppPackageInfoCommandLineInfo commandLineInfo = getGetAppPackageInfoCommandLineInfo(tmpArgs);
  try (AppPackage ap = newAppPackageInstance(new URI(args[1]), true)) {
    JSONSerializationProvider jomp = new JSONSerializationProvider();
    jomp.addSerializer(PropertyInfo.class,
        new AppPackage.PropertyInfoSerializer(commandLineInfo.provideDescription));
    JSONObject apInfo = new JSONObject(jomp.getContext(null).writeValueAsString(ap));
    apInfo.remove("name");
    printJson(apInfo);
  }
}
 
Example 5
Source File: LivyRestExecutor.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void livyLog(JSONObject logInfo, Logger logger) {
    for (String log: getLogs(logInfo)) {
        logger.log(log);
    }
    logInfo.remove("log");
    logger.log(logInfo.toString());
}