List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:blockplus.transport.BlockplusServerEvents.java
License:Open Source License
@Subscribe @AllowConcurrentEvents//from w w w . j av a 2 s . c o m public void onGameConnection(final IGameConnection gameConnection) { final IGame<Context> game = this.getServer().getGame(gameConnection.getOrdinal()); if (!game.isFull()) { final IClient oldClient = this.getServer().getClientByEndpoint(gameConnection.getEndpoint()); final IClient newClient = new Client(gameConnection.getEndpoint(), oldClient.getName(), game.getOrdinal()); this.getServer().updateClients(newClient.getEndpoint(), newClient); final BlockplusGame newGame = (BlockplusGame) game.connect(newClient); final ImmutableList<IClient> clients = newGame.getClients(); this.getServer().updateGame(newGame.getOrdinal(), newGame); final JsonObject gameInfo = new JsonObject(); gameInfo.addProperty("id", newGame.getOrdinal()); gameInfo.addProperty("players", clients.size()); newClient.getEndpoint().emit("game", gameInfo.toString()); final JsonObject playerInfo = new JsonObject(); playerInfo.addProperty("name", newClient.getName()); for (final IClient client : clients) { client.getEndpoint().emit("player", playerInfo.toString()); } this.getServer().removeFromPatio(newClient.getEndpoint()); for (final IEndPoint endPoint : this.getServer().getEndpointsInPatio()) { endPoint.emit("tables", this.getServer().games().toString()); } if (newGame.isFull() && !newGame.isPaused()) newGame.update(); } }
From source file:blockplus.transport.BlockplusServerEvents.java
License:Open Source License
@Subscribe @AllowConcurrentEvents//from w ww. ja v a2 s . c o m public void onNotification(final INotification notificationInterface) { final IClient client = this.getServer().getClientByEndpoint(notificationInterface.getEndpoint()); final Integer game = client.getGame(); final BlockplusGame blockplusGame = (BlockplusGame) this.getServer().getGame(game); final Colors from = Colors.valueOf(notificationInterface.getFrom()); final Colors to = Colors.valueOf(notificationInterface.getTo()); final String message = notificationInterface.getMessage(); final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("message", message); jsonObject.addProperty("from", from.toString()); jsonObject.addProperty("to", to.toString()); final IClient toClient = blockplusGame.getPlayer(to); toClient.getEndpoint().emit("notification", jsonObject.toString()); }
From source file:blockplus.transport.events.Client.java
License:Open Source License
@Override public String toString() { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("type", this.getClass().getSimpleName()); final JsonObject data = new JsonObject(); data.addProperty("name", this.getName()); data.addProperty("game", this.getGame().toString()); data.addProperty("io", this.getEndpoint().toString()); jsonObject.add("data", data); return jsonObject.toString(); }
From source file:blockplus.transport.messages.Client.java
License:Open Source License
@Override public JsonObject getData() { final JsonObject data = new JsonObject(); data.addProperty("name", this.getName()); return data;//from w ww . ja v a 2s.c o m }
From source file:blockplus.transport.messages.Client.java
License:Open Source License
@Override public String toString() { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("type", this.getType()); jsonObject.add("data", this.getData()); return jsonObject.toString(); }
From source file:blockplus.transport.messages.GameConnection.java
License:Open Source License
@Override public JsonObject getData() { final JsonObject data = new JsonObject(); data.addProperty("ordinal", this.getOrdinal()); return data;/*from w w w .j av a 2 s .c o m*/ }
From source file:blockplus.transport.messages.PauseResumeGame.java
License:Open Source License
@Override public JsonObject getData() { final JsonObject data = new JsonObject(); data.addProperty("isPaused", this.isPaused); return data;//from w w w .j a v a2s . c om }
From source file:bootwildfly.ProblemaJsonSerializer.java
@Override public JsonElement serialize(Problema p, Type type, JsonSerializationContext jsc) { //jsc.serialize() JsonObject object = new JsonObject(); TypeToken<List<Teste>> typeTestes = new TypeToken<List<Teste>>() { };/* ww w . j a v a2 s.c o m*/ JsonElement sumario = jsc.serialize(p.getSumario(), SumarioDeProblema.class); JsonElement testes = jsc.serialize(p.getTeste()); object.addProperty("id", p.getId()); object.addProperty("dica", p.getDica()); object.addProperty("isPublicado", p.isIsPublicado()); object.addProperty("isPublicado", p.isIsPublicado()); object.add("sumario", sumario); object.add("teste", testes); return object; }
From source file:br.com.apprestaurante.command.BuscarMesa.java
@Override public String execute(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(false); JsonObject json = new JsonObject(); PrintWriter out = null;//from w w w. j a va 2 s. c o m try { response.setContentType("application/json"); out = response.getWriter(); if (session == null) { json.addProperty("ok", "400"); } else { Mesa mesa = new MesaDao().getById(Integer.parseInt(request.getParameter("codigoMesa"))); json.addProperty("numero", mesa.getNumero()); } } catch (IOException ex) { Logger.getLogger(BuscarProduto.class.getName()).log(Level.SEVERE, null, ex); } out.print(json); out.flush(); return null; }
From source file:br.com.apprestaurante.servlet.MeuServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean isMultipart = ServletFileUpload.isMultipartContent(request); JsonObject json = new JsonObject(); response.setContentType("application/json"); PrintWriter out = response.getWriter(); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try {// ww w .j a v a 2 s . c o m List<FileItem> multiparts = upload.parseRequest(request); String caminho = request.getRequestURL().toString().replace(request.getRequestURI().toString(), "") + request.getContextPath() + "/imgs/"; System.out.println(System.getProperty("java.io.tmpdir")); for (FileItem item : multiparts) { if (item.getFieldName().equals("file")) { String nomeArquivo = new Date().getTime() + item.getName(); //File file = new File(getServletConfig().getServletContext().getRealPath("/imgs/").replace("build", ""), nomeArquivo); File file = new File(System.getProperty("java.io.tmpdir"), nomeArquivo); item.write(file); System.out.println(nomeArquivo); System.out.println(caminho + file.getName()); json.addProperty("caminho", file.getName()); } /*if (!item.isFormField()) { String name = new File(item.getName()).getName(); item.write(new File(name)); }*/ } out.print(json); out.flush(); } catch (Exception e) { e.printStackTrace(); System.out.println("File upload failed"); } } }