Skip to content

Instantly share code, notes, and snippets.

@raprasad
Created October 26, 2016 20:10
Show Gist options
  • Save raprasad/206347d5d0c678c08570e0c0e550019a to your computer and use it in GitHub Desktop.
Save raprasad/206347d5d0c678c08570e0c0e550019a to your computer and use it in GitHub Desktop.
GSON to JsonObjectBuilder
  • Go from a gsonObject object -> String -> jsonObjectBuilder
    public static JsonObjectBuilder convertGsonObjectToJsonObjectBuilder(String successMsg, JsonObject gsonObject) {
        JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
        jsonObjectBuilder.add("message", successMsg);
        JsonReader jsonReader = Json.createReader(new StringReader(gsonObject.toString()));
        javax.json.JsonObject object = jsonReader.readObject();
        jsonObjectBuilder.add("files", object.get("files"));
        return jsonObjectBuilder;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment