List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
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 ww w. j av a2s .com*/ }
From source file:blusunrize.immersiveengineering.client.models.ModelData.java
public static ModelData fromJson(JsonObject customData, Collection<String> knownKeys, String modelKey, ImmutableMap<String, String> texReplacements) { String baseLocStr = customData.get(modelKey).getAsString(); ResourceLocation baseLoc = new ResourceLocation(baseLocStr); JsonObject customBase = new JsonObject(); if (customData.has("custom")) customBase = customData.get("custom").getAsJsonObject(); for (Entry<String, JsonElement> e : customData.entrySet()) if (!knownKeys.contains(e.getKey()) && !customBase.has(e.getKey())) customBase.add(e.getKey(), e.getValue()); if (customData.has("textures")) { JsonObject obj = customData.get("textures").getAsJsonObject(); ImmutableMap.Builder<String, String> b = ImmutableMap.builder(); b.putAll(texReplacements);/*from w w w . jav a2 s . c om*/ b.putAll(asMap(obj, true)); texReplacements = b.build(); } return new ModelData(baseLoc, customBase, texReplacements); }
From source file:blusunrize.immersiveengineering.client.models.ModelData.java
public static JsonObject asJsonObject(Map<String, String> map) { JsonObject ret = new JsonObject(); JsonParser parser = new JsonParser(); for (Entry<String, String> e : map.entrySet()) { ret.add(e.getKey(), parser.parse(e.getValue())); }/*from www .j a v a2 s. c o m*/ return ret; }
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>>() { };/*from w w w . java 2 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 v a 2s . 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 {//w ww .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"); } } }
From source file:br.com.bean.Utilitarios.CriadorJson.java
public static String criaJsonErro(Exception e, String mensagem) { JsonObject jsonMensagemErro = new JsonObject(); jsonMensagemErro.addProperty("successo", "false"); jsonMensagemErro.addProperty("mensagem", mensagem); jsonMensagemErro.addProperty("exception", e.getMessage()); Gson gsonCorreto = new Gson(); return gsonCorreto.toJson(jsonMensagemErro); }
From source file:br.com.bean.Utilitarios.CriadorJson.java
public static String criaJsonSucesso(String mensagem) { JsonObject jsonMensagemSucesso = new JsonObject(); jsonMensagemSucesso.addProperty("successo", "true"); jsonMensagemSucesso.addProperty("mensagem", mensagem); Gson gsonCorreto = new Gson(); return gsonCorreto.toJson(jsonMensagemSucesso); }
From source file:br.com.caelum.vraptor.serialization.gson.MessageGsonConverter.java
License:Open Source License
@Override public JsonElement serialize(Message src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("category", src.getCategory()); json.addProperty("message", src.getMessage()); return json;/*from w w w . ja v a 2 s . co m*/ }
From source file:br.com.saude.api.social.gcm.GcmServer.java
License:Open Source License
/** * Send Ack message back to CCS to acknowledged the receipt of the message with ID msg_id. * * @param to Registration token of the sender of the message being acknowledged. * @param msg_id ID of message being acknowledged. *//*from w w w . ja va2 s .co m*/ private void sendAck(String to, String msg_id) { JsonObject jPayload = new JsonObject(); jPayload.addProperty("to", to); jPayload.addProperty("message_id", msg_id); jPayload.addProperty("message_type", "ack"); Gson gson = new GsonBuilder().setPrettyPrinting().create(); final String payload = gson.toJson(jPayload); Stanza stanza = new Stanza() { @Override public CharSequence toXML() { return wrapWithXML(payload); } }; logger.info("sending ack: " + stanza); smackCcsClient.sendStanza(stanza); }