Example usage for com.google.gson JsonArray size

List of usage examples for com.google.gson JsonArray size

Introduction

In this page you can find the example usage for com.google.gson JsonArray size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in the array.

Usage

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeListEvents(ListEvent list, JsonObject jObject) {
    JsonElement jElement = jObject.get(EVENT);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        Event event = new Event();
        getSinglePOI(event, jArray.get(i).getAsJsonObject());
        list.addEvent(event);//from  www  . jav a2 s.c o  m
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeListRoutes(ListRoute list, JsonObject jObject) {
    JsonElement jElement = jObject.get(ROUTES);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        Route route = new Route();
        getSinglePOI(route, jArray.get(i).getAsJsonObject());
        list.addRoute(route);/*w  w w  .  j a  va2  s  .  c  o m*/
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializePoiBased(Deserializable poi, JsonObject json) {
    getSinglePOI((POI) poi, json);//from w ww  .  j  a va 2  s. c o m

    // for routes
    if (json.has(POIS)) {
        JsonArray jArray = json.get(POIS).getAsJsonArray();
        ListPointOfInterest list = ((Route) poi).getListPoi();
        for (int i = 0; i < jArray.size(); i++) {
            PointOfInterest rPoi = new PointOfInterest();
            getSinglePOI(rPoi, jArray.get(i).getAsJsonObject());
            list.addPoi(rPoi);
        }
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeResources(Resources resources, JsonObject jObject) {
    JsonElement jElement = jObject.get(TOURISM);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        JsonObject ob = jArray.get(i).getAsJsonObject();
        HypermediaLink resource = getResource(ob);
        resources.addResource(resource);
    }//  w  ww  .  j ava  2  s .co m
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private POI deserializeCategories(Category list, JsonElement elem) {
    JsonObject json = null;/* w  w w . j a v  a  2s  . c o m*/
    JsonArray array;

    if (elem.isJsonObject() && elem.getAsJsonObject().has(CATEGORIES)) {
        array = elem.getAsJsonObject().get(CATEGORIES).getAsJsonArray();
        for (int i = 0; i < array.size(); i++) {
            Category cat = new Category();
            json = array.get(i).getAsJsonObject();
            getSinglePOI(cat, json);
            if (json.has(CATEGORIES)) {
                Category subs = (Category) deserializeCategories(new Category(), json);
                for (int j = 0; j < subs.getNumCategories(); j++)
                    cat.addCategory(subs.getCategory(j));
            }

            list.addCategory(cat);
        }
    }

    return list;
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeTag(POI tag, JsonArray array) {
    POI poi;/*from  ww w  .  j  a  va  2 s . c om*/
    for (int i = 0; i < array.size(); i++) {
        poi = new Tag();
        getSinglePOI(poi, array.get(i).getAsJsonObject());
        ((Tag) tag).addTag((Tag) poi);
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeTags(ListTag list, JsonObject jObject) {
    JsonObject json = null;//from  w ww . ja  v a  2s.c o  m
    JsonArray array;
    POI tag;

    array = jObject.get(TAGS).getAsJsonArray();
    for (int i = 0; i < array.size(); i++) {
        tag = new Tag();
        json = array.get(i).getAsJsonObject();
        deserializeTag(tag, json.get(TAG).getAsJsonArray());
        list.add((Tag) tag);
    }
}

From source file:client.commands.AutoPoints.java

License:Apache License

private void addPoints(JsonArray arr, int add, String chan) {
    for (int i = 0; i < arr.size(); i++) {
        String user = arr.get(i).getAsString();
        pts.AddPoints(user, add, chan);/*w  w  w  .  j a v  a  2 s  .c om*/
    }
}

From source file:co.cask.cdap.common.zookeeper.coordination.ResourceAssignmentTypeAdapter.java

License:Apache License

@Override
public ResourceAssignment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (!json.isJsonObject()) {
        throw new JsonParseException("Expect a json object, got " + json);
    }/*from   w ww  . j ava  2 s. co m*/

    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();

    Multimap<Discoverable, PartitionReplica> assignments = TreeMultimap
            .create(DiscoverableComparator.COMPARATOR, PartitionReplica.COMPARATOR);
    JsonArray assignmentsJson = context.deserialize(jsonObj.get("assignments"), JsonArray.class);
    for (JsonElement element : assignmentsJson) {
        if (!element.isJsonArray()) {
            throw new JsonParseException("Expect a json array, got " + element);
        }

        JsonArray entryJson = element.getAsJsonArray();
        if (entryJson.size() != 2) {
            throw new JsonParseException("Expect json array of size = 2, got " + entryJson.size());
        }
        Discoverable key = context.deserialize(entryJson.get(0), Discoverable.class);
        PartitionReplica value = context.deserialize(entryJson.get(1), PartitionReplica.class);
        assignments.put(key, value);
    }

    return new ResourceAssignment(name, assignments);
}

From source file:co.com.powersoft.lab.databaselab.controller.LineaGeneralServlet.java

/**
 * Metodo que permite insertar/*from  w  w w  . j av a  2 s.c o  m*/
 *
 * @autor Leonardo Solano
 * @param request contiene los datos pasados por AJAX
 * @param response contiene 1 si fue exitoso, 2 si ya existe o 0 si no fue
 * exitoso
 * @exception IOException
 */
public void agregarLineaGeneral(HttpServletRequest request, HttpServletResponse response) throws IOException {

    //Nombre de la operacin
    String OPERACION = OperationConstants.AGREGAR_LINEA_GENERAL;

    int resp = 0;

    try {

        //Objetos JSON
        String jsonElementos = request.getParameter("jsonElementos") == null ? "{}"
                : request.getParameter("jsonElementos");

        //Validamos que no sea vacio
        if (jsonElementos != null && !jsonElementos.equals("{}")) {

            Gson gson = new Gson();
            JsonObject result = gson.fromJson(jsonElementos, JsonElement.class).getAsJsonObject();
            //Nombre del prefijo del formulario
            String prefijo = "linea_";

            String idPlanta = request.getParameter("idPlanta") == null ? "0"
                    : HashEncripter.getInstance().desencrypterKey(request.getParameter("idPlanta"));

            //Validamos que exista un idPlanta
            if (!idPlanta.equals("0")) {
                JsonArray arrayCodigo = (JsonArray) result.get(prefijo + "codigo");
                JsonArray arrayNombre = (JsonArray) result.get(prefijo + "nombre");

                //Organizamos el objeto a agregar
                LineaGeneral lineaGeneral = new LineaGeneral();
                for (int i = 0; i < arrayCodigo.size(); i++) {
                    lineaGeneral.setCodigo(
                            arrayCodigo.get(i).getAsString().isEmpty() ? "" : arrayCodigo.get(i).getAsString());
                    lineaGeneral.setNombre(
                            arrayNombre.get(i).getAsString().isEmpty() ? "" : arrayNombre.get(i).getAsString());

                    PlantaGeneral plantaGeneral = new PlantaGeneral();
                    plantaGeneral.setId(Integer.parseInt(idPlanta));
                    lineaGeneral.setPlantaGeneral(plantaGeneral);
                }

                //Agregamos el objeto a la BD
                resp = ServiceFactory.getInstance().getServiceBeanLab().agregarLineaGeneral(usuario,
                        lineaGeneral);
            }
        }

        //Retornamos la respuesta al JSP
        respuestaServer(response, resp);

    } catch (NumberFormatException | JsonSyntaxException | NamingException e) {
        //Retornamos la respuesta al JSP
        respuestaServer(response, resp);
        logger.error(ErrorUtil.getInstance().getErrorData(e, OPERACION, INFO_ADICIONAL), e);
    } catch (Exception e) {
        logger.error(ErrorUtil.getInstance().getErrorData(e, OPERACION, INFO_ADICIONAL), e);
    }
}