Java Code Examples for com.google.gson.JsonStreamParser#hasNext()
The following examples show how to use
com.google.gson.JsonStreamParser#hasNext() .
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: MCRWCMSNavigationResource.java From mycore with GNU General Public License v3.0 | 6 votes |
@POST @Path("save") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response save(String json) throws Exception { JsonStreamParser jsonStreamParser = new JsonStreamParser(json); if (!jsonStreamParser.hasNext()) { return Response.status(Status.BAD_REQUEST).build(); } JsonObject saveObject = jsonStreamParser.next().getAsJsonObject(); // get navigation MCRNavigation newNavigation = MCRWCMSNavigationUtils.fromJSON(saveObject); // save navigation MCRWCMSNavigationUtils.save(newNavigation); // save content JsonArray items = saveObject.get(MCRWCMSNavigationProvider.JSON_ITEMS).getAsJsonArray(); getContentManager().save(items); return Response.ok().build(); }
Example 2
Source File: MCRCategUtils.java From mycore with GNU General Public License v3.0 | 6 votes |
public static HashMap<MCRCategoryID, String> getCategoryIDMap(String json) { HashMap<MCRCategoryID, String> categories = new HashMap<>(); JsonStreamParser jsonStreamParser = new JsonStreamParser(json); if (jsonStreamParser.hasNext()) { JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray(); for (JsonElement jsonElement : saveObjArray) { //jsonObject.item.id.rootid JsonObject root = jsonElement.getAsJsonObject(); String rootId = root.getAsJsonObject("item").getAsJsonObject("id").getAsJsonPrimitive("rootid") .getAsString(); String state = root.getAsJsonPrimitive("state").getAsString(); JsonElement parentIdJSON = root.get("parentId"); if (parentIdJSON != null && parentIdJSON.isJsonPrimitive() && "_placeboid_".equals(parentIdJSON.getAsString())) { state = "new"; } categories.put(MCRCategoryID.rootID(rootId), state); } } else { return null; } return categories; }
Example 3
Source File: ImagesService.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
private static void parseStreamToDisplayImageDownloadStatus(final InputStream inputStream) { InputStreamReader isr = new InputStreamReader(inputStream); BufferedReader reader = new BufferedReader(isr); JsonStreamParser parser = new JsonStreamParser(reader); while (parser.hasNext()) { JsonElement element = parser.next(); JsonObject object = element.getAsJsonObject(); if (object.has("status")) { System.out.print("."); } if (object.has("error")) { System.err.println("ERROR: " + object.get("error").getAsString()); } } System.out.println(""); }
Example 4
Source File: MCRClassificationEditorResource.java From mycore with GNU General Public License v3.0 | 5 votes |
@POST @Path("save") @MCRRestrictedAccess(MCRClassificationWritePermission.class) @Consumes(MediaType.APPLICATION_JSON) public Response save(String json) { JsonStreamParser jsonStreamParser = new JsonStreamParser(json); if (jsonStreamParser.hasNext()) { JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray(); List<JsonObject> saveList = new ArrayList<>(); for (JsonElement jsonElement : saveObjArray) { saveList.add(jsonElement.getAsJsonObject()); } saveList.sort(new IndexComperator()); for (JsonObject jsonObject : saveList) { String status = getStatus(jsonObject); SaveElement categ = getCateg(jsonObject); MCRJSONCategory parsedCateg = parseJson(categ.getJson()); if ("update".equals(status)) { new UpdateOp(parsedCateg, jsonObject).run(); } else if ("delete".equals(status)) { deleteCateg(categ.getJson()); } else { return Response.status(Status.BAD_REQUEST).build(); } } // Status.CONFLICT return Response.status(Status.OK).build(); } else { return Response.status(Status.BAD_REQUEST).build(); } }
Example 5
Source File: MiscService.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private static String parseSteamForImageId(final InputStream inputStream) { InputStreamReader isr = new InputStreamReader(inputStream); BufferedReader reader = new BufferedReader(isr); JsonStreamParser parser = new JsonStreamParser(reader); String imageId = null; while (parser.hasNext()) { JsonElement element = parser.next(); JsonObject object = element.getAsJsonObject(); if (object.has("stream")) { String text = object.get("stream").getAsString(); System.out.print(text); Matcher matcher = BUILD_IMAGE_ID_EXTRACTION_PATTERN.matcher(text); if (matcher.matches()) { imageId = matcher.group(2); } } if (object.has("status")) { System.out.println(object.get("status").getAsString()); } if (object.has("error")) { System.err.println("ERROR: " + object.get("error").getAsString()); } } return imageId; }