List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:beans.OrdenDeTrabajoPDF.java
private void createPdf(String dest) throws IOException, DocumentException { Parametrizacion p = new Parametrizacion(); this.listaPartes = new JsonParser().parse(ot.getPartes()).getAsJsonArray(); this.listaDescripcionesTrabajos = new JsonParser().parse(ot.getDescripcionesTrabajos()).getAsJsonArray(); this.listaMateriales = new JsonParser().parse(ot.getMateriales()).getAsJsonArray(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();/*from ww w . j av a 2s . c o m*/ PdfPTable table = new PdfPTable(12); BaseColor color = new BaseColor(142, 170, 219); PdfPCell celda; Phrase texto; Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10); table.setWidthPercentage(100); Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png"); celda = new PdfPCell(img, true); celda.setPadding(5); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("ORDEN DE TRABAJO N:" + this.ot.getNumeroOrdenDeTrabajo() + "\nFECHA INICIO:" + this.ot.getFechaInicio() + "\nFECHA FIN:" + this.ot.getFechaFin() + "\nSOLICITUD N:" + this.ot.getSolicitudDeMantenimiento().getCodigo() + "", font)); celda.setColspan(8); // head.setBackgroundColor(BaseColor.CYAN); table.addCell(celda); String tipoSolicitud = ot.getTipoSolicitud(); if (tipoSolicitud.equals("Urgente")) { celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD NORMAL: URGENTE: X", font)); celda.setColspan(12); table.addCell(celda); } else { celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD NORMAL: X URGENTE:", font)); celda.setColspan(12); table.addCell(celda); } if (ot.isDptAdmyControl()) { celda = new PdfPCell(new Phrase( "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI:X NO:", font)); celda.setColspan(12); table.addCell(celda); } else { celda = new PdfPCell(new Phrase( "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI: NO:X", font)); celda.setColspan(12); table.addCell(celda); } celda = new PdfPCell( new Phrase("CODIGO EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getCodigo(), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell( new Phrase("NOMBRE EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getNombre(), font)); celda.setColspan(9); table.addCell(celda); String tipoMantenimiento = ""; for (String element : ot.getTiposDeMantenimiento()) { tipoMantenimiento += element + "\n"; } celda = new PdfPCell(new Phrase("TIPO DE MANTENIMIENTO\n", font)); celda.setColspan(12); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase(tipoMantenimiento, font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("PARTE", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("ANOMALIA", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("CAUSA", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("POSIBLE SOLUCION", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); for (int i = 0; i < listaPartes.size(); i++) { celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("parte").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("anomalia").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("causa").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("solucion").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); } celda = new PdfPCell(new Phrase("SOLICTADA POR: " + ot.getSolicitadaPor() + "\n\nFIRMA", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("REVISADA POR: " + ot.getRevisadaPor() + "\n\nFIRMA", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("AUTORIZADA POR: " + ot.getAutorizadaPor() + "\n\nFIRMA", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("N", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS A REALIZAR", font)); celda.setColspan(11); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); for (int i = 0; i < listaDescripcionesTrabajos.size(); i++) { celda = new PdfPCell(new Phrase((i + 1) + "", font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase( listaDescripcionesTrabajos.get(i).getAsJsonObject().get("trabajo").toString().replace("\"", ""), font)); celda.setColspan(11); table.addCell(celda); } celda = new PdfPCell(new Phrase("MATERIALES", font)); celda.setColspan(12); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("N", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("CANTIDAD", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("REFERENCIA", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("VALOR UNI", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("VALOR TOTAL", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); for (int i = 0; i < listaMateriales.size(); i++) { celda = new PdfPCell(new Phrase("" + (1 + i), font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("cantidad").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("descripcion").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("referencia").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("unitario").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("total").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); } celda = new PdfPCell(new Phrase("COSTOS", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("MANO DE OBRA: $" + ot.getCostoManoDeObra() + "", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("MATERIALES: $" + ot.getCostoMateriales() + "", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL: $" + ot.getCostoTotal() + "", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("TIEMPO EMPLEADO", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + ot.getTotalHorasMto() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + ot.getTotalHorasParada() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS DAOS ENCONTRADOS", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + ot.getDescripcionDanos(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS REALIZADOS", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + ot.getDescripcionTrabajosRealizados(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("OBSERVACIONES Y RECOMENDACIONES", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + ot.getObservaciones(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("EJECUTO: " + ot.getEjecutadoPor() + "\n\nFIRMA", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("RECIBI Y APROB: " + ot.getRecibidoAprobadoPor() + "\n\nFIRMA", font)); celda.setColspan(6); table.addCell(celda); document.add(table); document.close(); }
From source file:blockplus.transport.VirtualClient.java
License:Open Source License
@Override public void onMessage(final String message) { final JsonParser jsonParser = new JsonParser(); final JsonObject jsonObject = jsonParser.parse(message).getAsJsonObject(); final String type = jsonObject.get("type").getAsString(); if (type.equals("game")) { final JsonObject data = jsonObject.get("data").getAsJsonObject(); final int k = data.get("players").getAsInt(); this.color = Colors.values()[k - 1].toString(); }/*from w w w . ja v a2 s . com*/ if (type.equals("update")) { final JsonObject data = jsonObject.get("data").getAsJsonObject(); // System.out.println(data); final String color = data.get("color").getAsString(); if (color.equals(this.color)) { if (data.get("isTerminal").getAsBoolean()) { System.out.println("Game Over"); } else { final Colors side = Colors.valueOf(this.color); final BoardEncoding boardEncoding = new BoardEncoding(); final Board board = boardEncoding.decode(data.get("board").getAsJsonObject()); // final OptionsEncoding optionsEncoding = new OptionsEncoding(); // final Options options = optionsEncoding.decode(data.get("options").getAsJsonObject()); final SidesEncoding sidesEncoding = new SidesEncoding(); final Sides sides = sidesEncoding.decode(data.get("pieces").getAsJsonObject()); final Context context = new Context(side, sides, board); final AI3 ai = new AI3(); // final IPosition position = this.testAI(side, board, options); // final Set<IPosition> positions = this.moveSupplier(options, position); System.out.println(); System.out.println(side); final Set<IPosition> positions = ai.get(context); final JsonArray jsonArray = new JsonArray(); for (final IPosition iPosition : positions) jsonArray.add(new JsonPrimitive(20 * iPosition.row() + iPosition.column() % 20)); // TODO !!! final MoveSubmit moveSubmit = new MoveSubmit(jsonArray); try { this.send(moveSubmit); } catch (final Exception e) { } } } } }
From source file:blusunrize.immersiveengineering.client.ClientProxy.java
public void addChangelogToManual() { FontRenderer fr = ManualHelper.getManual().fontRenderer; boolean isUnicode = fr.getUnicodeFlag(); fr.setUnicodeFlag(true);//from ww w . j a v a 2 s . co m SortedMap<ComparableVersion, Pair<String, IManualPage[]>> allChanges = new TreeMap<>( Comparator.reverseOrder()); ComparableVersion currIEVer = new ComparableVersion(ImmersiveEngineering.VERSION); //Included changelog try (InputStream in = Minecraft.getMinecraft().getResourceManager() .getResource(new ResourceLocation(ImmersiveEngineering.MODID, "changelog.json")).getInputStream()) { JsonElement ele = new JsonParser().parse(new InputStreamReader(in)); JsonObject upToCurrent = ele.getAsJsonObject(); for (Entry<String, JsonElement> entry : upToCurrent.entrySet()) { ComparableVersion version = new ComparableVersion(entry.getKey()); Pair<String, IManualPage[]> manualEntry = addVersionToManual(currIEVer, version, entry.getValue().getAsString(), false); if (manualEntry != null) allChanges.put(version, manualEntry); } } catch (IOException x) { x.printStackTrace(); } //Changelog from update JSON CheckResult result = ForgeVersion.getResult(Loader.instance().activeModContainer()); if (result.status != Status.PENDING && result.status != Status.FAILED) for (Entry<ComparableVersion, String> e : result.changes.entrySet()) allChanges.put(e.getKey(), addVersionToManual(currIEVer, e.getKey(), e.getValue(), true)); for (Pair<String, IManualPage[]> entry : allChanges.values()) ManualHelper.addEntry(entry.getLeft(), ManualHelper.CAT_UPDATE, entry.getRight()); fr.setUnicodeFlag(isUnicode); }
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 w w w . j a v a 2s.c om return ret; }
From source file:blusunrize.immersiveengineering.client.models.multilayer.MultiLayerModel.java
@Nonnull @Override//ww w .ja v a2 s. c o m public IModel process(ImmutableMap<String, String> customData) { Map<BlockRenderLayer, List<ModelData>> newSubs = new HashMap<>(); JsonParser parser = new JsonParser(); Map<String, String> unused = new HashMap<>(); for (String layerStr : customData.keySet()) if (LAYERS_BY_NAME.containsKey(layerStr)) { BlockRenderLayer layer = LAYERS_BY_NAME.get(layerStr); JsonElement ele = parser.parse(customData.get(layerStr)); if (ele.isJsonObject()) { ModelData data = ModelData.fromJson(ele.getAsJsonObject(), ImmutableList.of(), ImmutableMap.of()); newSubs.put(layer, ImmutableList.of(data)); } else if (ele.isJsonArray()) { JsonArray array = ele.getAsJsonArray(); List<ModelData> models = new ArrayList<>(); for (JsonElement subEle : array) if (subEle.isJsonObject()) models.add(ModelData.fromJson(ele.getAsJsonObject(), ImmutableList.of(), ImmutableMap.of())); newSubs.put(layer, models); } } else unused.put(layerStr, customData.get(layerStr)); JsonObject unusedJson = ModelData.asJsonObject(unused); for (Entry<BlockRenderLayer, List<ModelData>> entry : newSubs.entrySet()) for (ModelData d : entry.getValue()) for (Entry<String, JsonElement> entryJ : unusedJson.entrySet()) if (!d.data.has(entryJ.getKey())) d.data.add(entryJ.getKey(), entryJ.getValue()); if (!newSubs.equals(subModels)) return new MultiLayerModel(newSubs); return this; }
From source file:bmw.assigment.BMWAssigment.java
/** * For this reading I used GSON, a library made by google to parse JSON objects * In order for this to run propertly, a file employees.json must be in the path /resources/employees.json * /*w w w. j av a 2 s. c o m*/ * @return JsonObject */ public JsonObject readJsonFile() { JsonObject employeeRoot = null; try { InputStream str = BMWAssigment.class.getResourceAsStream("/resources/employees.json"); JsonReader reader = new JsonReader(new InputStreamReader(str)); JsonParser jsonParser = new JsonParser(); employeeRoot = jsonParser.parse(reader).getAsJsonObject(); reader.close(); str.close(); } catch (IOException ex) { Logger.getLogger(BMWAssigment.class.getName()).log(Level.SEVERE, null, ex); } return employeeRoot; }
From source file:br.com.anteros.social.facebook.utils.JsonUtils.java
License:Apache License
public static <T> T fromJson(String json, Class<T> cls) { Gson gson = buildGson();//from w w w. j a v a 2 s.co m JsonParser parser = new JsonParser(); JsonElement element = parser.parse(json); if (cls != null && cls.isArray() && element instanceof JsonArray == false) { JsonArray jsonArray = new JsonArray(); jsonArray.add(element); Type listType = new TypeToken<T>() { }.getType(); return gson.fromJson(jsonArray, listType); } return gson.fromJson(json, cls); }
From source file:br.com.anteros.social.facebook.utils.JsonUtils.java
License:Apache License
public static <T> T fromJson(String json, Type type) { Gson gson = buildGson();//from w w w . ja va2s .c o m JsonParser parser = new JsonParser(); JsonElement element = parser.parse(json); return gson.fromJson(element, type); }
From source file:br.com.anteros.social.facebook.utils.JsonUtils.java
License:Apache License
public static <T> T fromJsonExcludeFields(String json, Class<T> cls) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); JsonParser parser = new JsonParser(); JsonElement element = parser.parse(json); if (cls.isArray() && element instanceof JsonArray == false) { JsonArray jsonArray = new JsonArray(); jsonArray.add(element);//from ww w .j a v a 2s. c o m Type listType = new TypeToken<T>() { }.getType(); return gson.fromJson(jsonArray, listType); } return gson.fromJson(json, cls); }
From source file:br.com.caelum.vraptor.serialization.gson.GsonDeserialization.java
License:Open Source License
@Override public Object[] deserialize(InputStream inputStream, ControllerMethod method) { Class<?>[] types = getTypes(method); if (types.length == 0) { throw new IllegalArgumentException( "Methods that consumes representations must receive just one argument"); }//from w ww . j a v a 2 s . c o m Gson gson = builder.create(); final Parameter[] parameterNames = paramNameProvider.parametersFor(method.getMethod()); final Object[] values = new Object[parameterNames.length]; final Deserializee deserializee = deserializeeInstance.get(); try { String content = getContentOfStream(inputStream); logger.debug("json retrieved: {}", content); if (!isNullOrEmpty(content)) { JsonParser parser = new JsonParser(); JsonElement jsonElement = parser.parse(content); if (jsonElement.isJsonObject()) { JsonObject root = jsonElement.getAsJsonObject(); deserializee.setWithoutRoot(isWithoutRoot(parameterNames, root)); for (Class<? extends DeserializerConfig> option : method.getMethod() .getAnnotation(Consumes.class).options()) { DeserializerConfig config = container.instanceFor(option); config.config(deserializee); } for (int i = 0; i < types.length; i++) { Parameter parameter = parameterNames[i]; JsonElement node = root.get(parameter.getName()); if (deserializee.isWithoutRoot()) { values[i] = gson.fromJson(root, fallbackTo(parameter.getParameterizedType(), types[i])); logger.info("json without root deserialized"); break; } else if (node != null) { if (node.isJsonArray()) { JsonArray jsonArray = node.getAsJsonArray(); Type type = parameter.getParameterizedType(); if (type instanceof ParameterizedType) { values[i] = gson.fromJson(jsonArray, type); } else { values[i] = gson.fromJson(jsonArray, types[i]); } } else { values[i] = gson.fromJson(node, types[i]); } } } } else if (jsonElement.isJsonArray()) { if ((parameterNames.length != 1) || (!(parameterNames[0].getParameterizedType() instanceof ParameterizedType))) throw new IllegalArgumentException( "Methods that consumes an array representation must receive only just one collection generic typed argument"); JsonArray jsonArray = jsonElement.getAsJsonArray(); values[0] = gson.fromJson(jsonArray, parameterNames[0].getParameterizedType()); } else { throw new IllegalArgumentException("This is an invalid or not supported json content"); } } } catch (Exception e) { throw new ResultException("Unable to deserialize data", e); } logger.debug("json deserialized: {}", (Object) values); return values; }