List of usage examples for com.google.gson JsonArray add
public void add(JsonElement element)
From source file:com.google.samples.apps.iosched.sync.userdata.util.UserActionHelper.java
License:Open Source License
public static String serializeUserActions(List<UserAction> actions) { JsonArray array = new JsonArray(); for (UserAction action : actions) { JsonObject obj = new JsonObject(); obj.add("type", new JsonPrimitive(action.type.name())); obj.add("id", new JsonPrimitive(action.sessionId)); array.add(obj); }//from ww w . j a va 2s . c om return array.toString(); }
From source file:com.google.samples.apps.iosched.sync.userdata.util.UserDataHelper.java
License:Open Source License
static public String toSessionsString(Set<String> sessionIds) { JsonArray array = new JsonArray(); for (String sessionId : sessionIds) { array.add(new JsonPrimitive(sessionId)); }// w ww . j ava 2 s. c o m JsonObject obj = new JsonObject(); obj.add(JSON_STARRED_SESSIONS_KEY, array); return obj.toString(); }
From source file:com.google.u2f.gaedemo.servlets.BeginEnrollServlet.java
License:Open Source License
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { User user = userService.getCurrentUser(); boolean singleEnrollment = !Boolean.valueOf(req.getParameter("reregistration")); RegistrationRequest registrationRequest; List<SignRequest> signRequests; try {/*from w ww . j av a 2s. c om*/ registrationRequest = u2fServer.getRegistrationRequest(user.getUserId(), (req.isSecure() ? "https://" : "http://") + req.getHeader("Host")); if (singleEnrollment) { signRequests = u2fServer.getSignRequest(user.getUserId(), (req.isSecure() ? "https://" : "http://") + req.getHeader("Host")); } else { signRequests = ImmutableList.of(); } } catch (U2FException e) { throw new ServletException("couldn't get registration request", e); } JsonArray signData = new JsonArray(); for (SignRequest signRequest : signRequests) { JsonObject signServerData = new JsonObject(); signServerData.addProperty("appId", signRequest.getAppId()); signServerData.addProperty("challenge", signRequest.getChallenge()); signServerData.addProperty("version", signRequest.getVersion()); signServerData.addProperty("keyHandle", signRequest.getKeyHandle()); signData.add(signServerData); } JsonObject enrollData = new JsonObject(); enrollData.addProperty("appId", registrationRequest.getAppId()); enrollData.addProperty("challenge", registrationRequest.getChallenge()); enrollData.addProperty("version", registrationRequest.getVersion()); JsonObject result = new JsonObject(); result.add("enroll_data", enrollData); result.add("sign_data", signData); result.addProperty("sessionId", registrationRequest.getSessionId()); resp.setContentType("application/json"); resp.getWriter().println(result.toString()); }
From source file:com.google.u2f.gaedemo.servlets.BeginSignServlet.java
License:Open Source License
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { User user = userService.getCurrentUser(); List<SignRequest> signRequests; try {/*w w w. j a v a 2 s.c om*/ signRequests = u2fServer.getSignRequest(user.getUserId(), (req.isSecure() ? "https://" : "http://") + req.getHeader("Host")); } catch (U2FException e) { throw new ServletException("couldn't get registration request", e); } JsonArray result = new JsonArray(); for (SignRequest signRequest : signRequests) { JsonObject signServerData = new JsonObject(); signServerData.addProperty("appId", signRequest.getAppId()); signServerData.addProperty("challenge", signRequest.getChallenge()); signServerData.addProperty("version", signRequest.getVersion()); signServerData.addProperty("keyHandle", signRequest.getKeyHandle()); signServerData.addProperty("sessionId", signRequest.getSessionId()); result.add(signServerData); } resp.setContentType("application/json"); resp.getWriter().println(result.toString()); }
From source file:com.google.u2f.gaedemo.servlets.GetTokensServlet.java
License:Open Source License
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { User user = userService.getCurrentUser(); UserTokens tokens = Objects.firstNonNull(ofy().load().type(UserTokens.class).id(user.getUserId()).now(), new UserTokens(user.getUserId())); JsonArray resultList = new JsonArray(); for (TokenStorageData token : tokens.getTokens()) { resultList.add(token.toJson()); }//from w w w.ja va 2 s . c o m resp.setContentType("application/json"); resp.getWriter().println(resultList.toString()); }
From source file:com.google.u2f.server.messages.RegisteredKey.java
License:Open Source License
private JsonArray getTransportsAsJsonArray() { JsonArray transportsArray = new JsonArray(); for (Transports transport : this.transports) { transportsArray.add(new JsonPrimitive(transport.toString())); }// w w w .j a v a 2s . c o m return transportsArray; }
From source file:com.google.u2f.server.messages.U2fSignRequest.java
License:Open Source License
public JsonArray getRegisteredKeysAsJson(String defaultAppId) { if (registeredKeys == null) { return null; }// www. j a va2s . co m JsonArray result = new JsonArray(); for (RegisteredKey registeredKey : registeredKeys) { result.add(registeredKey.getJson(defaultAppId)); } return result; }
From source file:com.google.u2f.tools.httpserver.servlets.SignDataServlet.java
License:Open Source License
@Override public void generateJavascript(Request req, Response resp, PrintStream body) throws Exception { String userName = req.getParameter("userName"); if (userName == null) { resp.setStatus(Status.BAD_REQUEST); return;/*from ww w . j av a 2 s . co m*/ } List<SignRequest> signRequests = u2fServer.getSignRequest(userName, "http://localhost:8080"); JsonArray result = new JsonArray(); for (SignRequest signRequest : signRequests) { JsonObject signServerData = new JsonObject(); signServerData.addProperty("appId", signRequest.getAppId()); signServerData.addProperty("challenge", signRequest.getChallenge()); signServerData.addProperty("version", signRequest.getVersion()); signServerData.addProperty("sessionId", signRequest.getSessionId()); signServerData.addProperty("keyHandle", signRequest.getKeyHandle()); result.add(signServerData); } body.println("var signData = " + result.toString() + ";"); }
From source file:com.google.walkaround.proto.gson.RobotSearchDigestGsonImpl.java
License:Apache License
/** * Static implementation-independent GSON serializer. Call this from * {@link #toGson} to avoid subclassing issues with inner message types. *//*from ww w . jav a2s . c om*/ public static JsonElement toGsonHelper(RobotSearchDigest message, RawStringData raw, Gson gson) { JsonObject json = new JsonObject(); json.add("1", new JsonPrimitive(message.getWaveId())); { JsonArray array = new JsonArray(); for (int i = 0; i < message.getParticipantSize(); i++) { array.add(new JsonPrimitive(message.getParticipant(i))); } json.add("2", array); } json.add("3", new JsonPrimitive(message.getTitle())); json.add("4", new JsonPrimitive(message.getSnippet())); json.add("5", GsonUtil.toJson(message.getLastModifiedMillis())); json.add("6", new JsonPrimitive(message.getBlipCount())); json.add("7", new JsonPrimitive(message.getUnreadBlipCount())); return json; }
From source file:com.google.walkaround.wave.server.rpc.ContactsHandler.java
License:Open Source License
/** * Prints a contact feed as JSON into a servlet response. *///from w w w . j a v a 2 s . c o m private void printJson(ContactFeed results, String encodedAddress, HttpServletResponse resp) throws IOException { // Since the fetch API is index based, this handler must return exactly one // result per contact entry. If a contact has 0 email addresses, then an // empty contact is returned, since without the email address, the // information is useless. If a contact has >1 email addresses, a contact // object based on just the first one is returned, due to the // exactly-one-result-per-feed-entry constraint. JsonArray res = new JsonArray(); for (ContactEntry e : results.getEntries()) { JsonObject contact = new JsonObject(); List<Email> emails = e.getEmailAddresses(); if (!emails.isEmpty()) { contact.add("a", new JsonPrimitive(emails.get(0).getAddress())); contact.add("n", new JsonPrimitive(e.getTitle().getPlainText())); contact.add("p", new JsonPrimitive(shortPhotoUrl(encodedAddress, e.getContactPhotoLink()))); } res.add(contact); } resp.getWriter().print(SharedConstants.XSSI_PREFIX + "(" + res.toString() + ")"); }