private JsonObject createJson() {
        JsonObject json = new JsonObject();
        addProperty(json, "cancel", cancel);
        addProperty(json, "continuous", continuous);
        addProperty(json, "filter", filter);

        if (queryParams != null) {
            json.add("query_params", queryParams);
        }
        if (docIds != null) {
            json.add("doc_ids", client.getGson().toJsonTree(docIds, String[].class));
        }

        addProperty(json, "proxy", proxy);
        addProperty(json, "since_seq", sinceSeq);
        addProperty(json, "create_target", createTarget);

        // source

        if (sourceIamApiKey == null) {
            addProperty(json, "source", source);
        } else {
            JsonObject sourceAuthJson = new JsonObject();
            JsonObject sourceIamJson = new JsonObject();
            addProperty(sourceIamJson, "api_key", sourceIamApiKey);
            sourceAuthJson.add("iam", sourceIamJson);

            JsonObject sourceJson = new JsonObject();
            addProperty(sourceJson, "url", source);
            sourceJson.add("auth", sourceAuthJson);

            json.add("source", sourceJson);
        }

        // target

        JsonObject targetAuth = new JsonObject();

        if (targetIamApiKey != null) {
            JsonObject targetIamJson = new JsonObject();
            addProperty(targetIamJson, "api_key", targetIamApiKey);
            targetAuth.add("iam", targetIamJson);
        }
        if (targetOauth != null) {
            // Note: OAuth is only supported on replication target (not source)
            JsonObject oauth = new JsonObject();
            addProperty(oauth, "consumer_secret", consumerSecret);
            addProperty(oauth, "consumer_key", consumerKey);
            addProperty(oauth, "token_secret", tokenSecret);
            addProperty(oauth, "token", token);
            targetAuth.add("oauth", oauth);
        }

        if (targetAuth.size() == 0) {
            addProperty(json, "target", target);
        } else {
            JsonObject targetJson = new JsonObject();
            addProperty(targetJson, "url", target);
            targetJson.add("auth", targetAuth);

            json.add("target", targetJson);
        }

        return json;
    }
private JsonObject createJson ( ) { JsonObject json = new JsonObject ( ) ; addProperty ( json , "cancel" , cancel ) ; addProperty ( json , "continuous" , continuous ) ; addProperty ( json , "filter" , filter ) ; if ( queryParams != null ) { json . add ( "query_params" , queryParams ) ; } if ( docIds != null ) { json . add ( "doc_ids" , client . getGson ( ) . toJsonTree ( docIds , String [ ] . class ) ) ; } addProperty ( json , "proxy" , proxy ) ; addProperty ( json , "since_seq" , sinceSeq ) ; addProperty ( json , "create_target" , createTarget ) ; if ( sourceIamApiKey == null ) { addProperty ( json , "source" , source ) ; } else { JsonObject sourceAuthJson = new JsonObject ( ) ; JsonObject sourceIamJson = new JsonObject ( ) ; addProperty ( sourceIamJson , "api_key" , sourceIamApiKey ) ; sourceAuthJson . add ( "iam" , sourceIamJson ) ; JsonObject sourceJson = new JsonObject ( ) ; addProperty ( sourceJson , "url" , source ) ; sourceJson . add ( "auth" , sourceAuthJson ) ; json . add ( "source" , sourceJson ) ; } JsonObject targetAuth = new JsonObject ( ) ; if ( targetIamApiKey != null ) { JsonObject targetIamJson = new JsonObject ( ) ; addProperty ( targetIamJson , "api_key" , targetIamApiKey ) ; targetAuth . add ( "iam" , targetIamJson ) ; } if ( targetOauth != null ) { JsonObject oauth = new JsonObject ( ) ; addProperty ( oauth , "consumer_secret" , consumerSecret ) ; addProperty ( oauth , "consumer_key" , consumerKey ) ; addProperty ( oauth , "token_secret" , tokenSecret ) ; addProperty ( oauth , "token" , token ) ; targetAuth . add ( "oauth" , oauth ) ; } if ( targetAuth . size ( ) == 0 ) { addProperty ( json , "target" , target ) ; } else { JsonObject targetJson = new JsonObject ( ) ; addProperty ( targetJson , "url" , target ) ; targetJson . add ( "auth" , targetAuth ) ; json . add ( "target" , targetJson ) ; } return json ; }
helper