List of usage examples for com.google.gson JsonObject remove
public JsonElement remove(String property)
From source file:org.tuleap.mylyn.task.core.internal.serializer.TuleapArtifactWithCommentSerializer.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j a v a 2 s . c o m * * @see com.google.gson.JsonSerializer#serialize(java.lang.Object, java.lang.reflect.Type, * com.google.gson.JsonSerializationContext) */ @Override public JsonElement serialize(U commentedArtifact, Type type, JsonSerializationContext context) { JsonObject elementObject = (JsonObject) super.serialize(commentedArtifact, type, context); elementObject.remove(ITuleapConstants.ID); String comment = commentedArtifact.getNewComment(); if (comment != null && !comment.isEmpty()) { JsonObject commentObject = new JsonObject(); elementObject.add(ITuleapConstants.COMMENT, commentObject); commentObject.add(ITuleapConstants.BODY, new JsonPrimitive(comment)); commentObject.add(ITuleapConstants.FORMAT, new JsonPrimitive("text")); //$NON-NLS-1$ } return elementObject; }
From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.debugger.channel.messagefactory.impl.JsonGsonMessageFactory.java
License:Open Source License
@Override public JsonObject createMediatorLocationJsonObj(AbstractESBDebugPointMessage debugPoint) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(ESBMediatorPosition.class, new MediatorPositionGsonSerializer()); builder.setFieldNamingStrategy(new PojoToGsonCustomNamingStrategy()); Gson debugPointMessage = builder.create(); String jsonString = debugPointMessage.toJson(debugPoint); JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject(); jsonObject.remove(COMMAND_ARGUMENT_LABEL); return jsonObject; }
From source file:ostepu.cconfig.control.java
License:Open Source License
/** * ruft die existierende Konfiguration ab und gibt sie aus * * @param context der Kontext des Servlet * @param request die eingehende Anfrage * @param response das Antwortobjekt/* w ww. j a v a2 s . co m*/ */ public static void getControl(ServletContext context, HttpServletRequest request, HttpServletResponse response) { PrintWriter out; try { out = response.getWriter(); } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); return; } Path cconfigPath = Paths.get(context.getRealPath("/data/CConfig.json")); try { if (Files.exists(cconfigPath)) { List<String> content = Files.readAllLines(cconfigPath); JsonElement obj = new JsonParser().parse(String.join("", content)); JsonObject newObject = obj.getAsJsonObject(); if (newObject.has("prefix")) { newObject.remove("prefix"); newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } else { newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } out.print(newObject.toString()); response.setStatus(200); } else { response.setStatus(404); out.print("[]"); } } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); } finally { out.close(); } }
From source file:ostepu.cconfig.control.java
License:Open Source License
/** * setzt die Konfiguration der Komponente anhand der eingehenden Daten * * @param context der Kontext des Servlet * @param request die eingehende Anfrage * @param response das Antwortobjekt/* ww w . ja va 2 s . c o m*/ */ public static void setControl(ServletContext context, HttpServletRequest request, HttpServletResponse response) { PrintWriter out; try { out = response.getWriter(); } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); return; } Path cconfigPath = Paths.get(context.getRealPath("/data/CConfig.json")); try { String q = IOUtils.toString(request.getReader()); JsonElement obj = new JsonParser().parse(q); JsonObject newObject = obj.getAsJsonObject(); if (newObject.has("prefix")) { newObject.remove("prefix"); newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } else { newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } Files.write(cconfigPath, newObject.toString().getBytes()); cconfig.myConf = null; response.setStatus(201); } catch (IOException | JsonSyntaxException e) { try { response.sendError(500); } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); } } finally { if (out != null) { out.close(); } } }
From source file:ph.fingra.sdklogger.util.JsonLoggerRunnable.java
License:Apache License
private String getLogFromJsonobject(JsonObject jObject, String[] keys, StringBuffer sb) { String jString = null;//from ww w .j a v a 2 s .co m for (String key : keys) { JsonElement jElement = jObject.remove(key); if (jElement == null) { //not exist key/value pair -> NULL Text append sb.append(LOG_EMPTY_VALUE); sb.append(SDK_LOG_SEPERATOR); continue; } jString = jElement.getAsString(); if (jString.isEmpty()) { sb.append(LOG_EMPTY_VALUE); sb.append(SDK_LOG_SEPERATOR); continue; } else { sb.append(jString); } sb.append(SDK_LOG_SEPERATOR); } return jString; }
From source file:rest.FlightReservation.java
@POST @Produces(MediaType.APPLICATION_JSON)/*from ww w. j a v a2 s .c o m*/ public Response reservation(String jsonReservation) throws IOException, JSONException, FlightException { JsonObject jsonObj = new JsonParser().parse(jsonReservation).getAsJsonObject(); FlightInstance flight = em.find(FlightInstance.class, jsonObj.get("flightID").getAsString()); int numberOfSeats = 0; try { numberOfSeats = Integer.parseInt(jsonObj.get("numberOfSeats").getAsString()); } catch (Exception e) { } if (flight.getAvailableSeats() > numberOfSeats) { flight.setAvailableSeats(flight.getAvailableSeats() - numberOfSeats); em.getTransaction().begin(); em.merge(flight); em.getTransaction().commit(); jsonObj.remove("ReservePhone"); jsonObj.remove("ReserveeEmail"); jsonObj.addProperty("Origin", flight.getOrigin().getCity() + " (" + flight.getOrigin().getIatacode() + ")"); jsonObj.addProperty("Destination", flight.getDestination().getCity() + " (" + flight.getDestination().getIatacode() + ")"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Date date = flight.getDepartureDate(); Date time = flight.getDepartureTime(); date.setHours(time.getHours()); date.setMinutes(time.getMinutes()); String newDate = df.format(date); jsonObj.addProperty("Date", newDate); jsonObj.addProperty("FlightTime", flight.getTravelTime()); } else throw new FlightException("Not enough available seats"); return Response.accepted(gson.toJson(jsonObj)).build(); }
From source file:rest.MomondoRest.java
@POST @Consumes("application/json") @Produces("application/json") public Response reservationRequest(String jsonString) throws IOException { Post p = new Post(); JsonObject js = new JsonParser().parse(jsonString).getAsJsonObject(); String url = js.get("url").getAsString(); js.remove("url"); String finalJs = js.toString(); String stringResponse = p.postReservation(url, finalJs); return Response.status(Response.Status.OK).entity(stringResponse).build(); }
From source file:se.sperber.cryson.serialization.CrysonSerializer.java
License:Apache License
private void transformJsonObjectToUnauthorizedEntity(JsonObject jsonObject) { for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { if (!allowedUnauthorizedAttributeNames.contains(entry.getKey())) { jsonObject.remove(entry.getKey()); }/*from w ww .j a v a2 s. c o m*/ } jsonObject.addProperty("crysonUnauthorized", true); }
From source file:servlets.Install_servlets.java
License:Open Source License
private JsonObject readDockerEnvParams() throws IOException { JsonObject settings = new JsonObject(); //Set the default values settings.addProperty("EMS_ADMIN_USER", "emsadminuser@email.com"); settings.addProperty("EMS_ADMIN_PASSWORD", "emsadminuser@email.com"); settings.addProperty("MYSQL_ROOT_USER", "root"); settings.addProperty("MYSQL_ROOT_PASSWORD", ""); settings.addProperty("MYSQL_DATABASE_NAME", "STATegraDB"); settings.addProperty("MYSQL_HOST", "stategraems-mysql"); settings.addProperty("MYSQL_EMS_USER", "emsuser"); settings.addProperty("MYSQL_EMS_PASS", getRandomPass()); settings.addProperty("data_location", "/data/stategraems_app_data/"); //Read the enviroment variables. String path = Install_servlets.class.getResource("/servlets/servlets_resources").getPath(); String[] command = { "/bin/bash", path + "readDockerEnvParams" }; Process process = Runtime.getRuntime().exec(command); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String inputLine, key, value; while ((inputLine = bufferedReader.readLine()) != null) { key = inputLine.split(":", 2)[0].replaceAll(" ", ""); value = inputLine.split(":", 2)[1].replaceAll("\"", "").replaceAll("\'", "").replaceAll(" ", ""); if (settings.has(key)) { settings.remove(key); }/* w ww . j a v a2 s. c om*/ settings.addProperty(key, value); } bufferedReader.close(); return settings; }
From source file:uk.ac.horizon.artcodes.server.utils.ExperienceItems.java
License:Open Source License
private static JsonObject verifyExperience(JsonElement element) throws HTTPException { if (!element.isJsonObject()) { throw new HTTPException(HttpServletResponse.SC_BAD_REQUEST, "Expected object"); }/*from w ww .j a va 2 s. c o m*/ JsonObject jsonObject = element.getAsJsonObject(); jsonObject.remove("editable"); return jsonObject; }