List of usage examples for com.google.gson JsonObject size
public int size()
From source file:login.SelectIP.java
private void setUpBaseData() throws IOException { final UpdateInterface update1 = lb.getRetrofit().create(UpdateInterface.class); final RefralAPI refralAPI = lb.getRetrofit().create(RefralAPI.class); final JsonObject branchMaster = update1.GetBranchMaster().execute().body(); final JsonObject refmaster = refralAPI.GetSalesmanMaster().execute().body(); final JsonArray branchArray = branchMaster.getAsJsonArray("data"); final JsonArray refMaster = refmaster.getAsJsonArray("data"); final JsonArray yearArray = branchMaster.getAsJsonArray("year"); if (branchArray.size() > 0) { for (int i = 0; i < branchArray.size(); i++) { BranchMasterModel model = new Gson().fromJson(branchArray.get(i).getAsJsonObject().toString(), BranchMasterModel.class); Constants.BRANCH.add(model); }// w w w. ja va 2 s . c o m } if (yearArray.size() > 0) { for (int i = 0; i < yearArray.size(); i++) { DBYearModel model = new Gson().fromJson(yearArray.get(i).getAsJsonObject().toString(), DBYearModel.class); Constants.DBYMS.add(model); } } if (refMaster.size() > 0) { for (int i = 0; i < refMaster.size(); i++) { RefModel model = new Gson().fromJson(refMaster.get(i).getAsJsonObject().toString(), RefModel.class); Constants.REFERAL.add(model); } } getTaxMaster(); }
From source file:nz.co.lolnet.mercury.authentication.Authentication.java
License:Apache License
public Response checkAuthentication(String request, List<String> permissions) { try {/* ww w.j a va 2 s . c o m*/ if (StringUtils.isBlank(request)) { return Response.status(Status.BAD_REQUEST) .entity(MercuryUtil.createErrorResponse("Bad Request", "Blank request")).build(); } JsonObject jsonObject = new JsonParser() .parse(new String(Base64.getUrlDecoder().decode(request), StandardCharsets.UTF_8)) .getAsJsonObject(); Data data = new Gson().fromJson(jsonObject, Data.class); if (data == null) { return Response.status(Status.BAD_REQUEST) .entity(MercuryUtil.createErrorResponse("Bad Request", "Invalid data")).build(); } uniqueId = data.getUniqueId(); account = Mercury.getInstance().getConfig().getAccounts().get(getUniqueId()); if (getAccount() == null) { return Response.status(Status.BAD_REQUEST) .entity(MercuryUtil.createErrorResponse("Bad Request", "Supplied UniqueId does not exist")) .build(); } if (StringUtils.isBlank(data.getMessage())) { return Response.status(Status.BAD_REQUEST) .entity(MercuryUtil.createErrorResponse("Bad Request", "Request contained no data")) .build(); } jsonObject = new JsonParser().parse(doDecrypt(data.getMessage())).getAsJsonObject(); if (jsonObject == null || !jsonObject.has("creationTime") || !isRequestValid(jsonObject.remove("creationTime").getAsLong())) { return Response.status(Status.FORBIDDEN) .entity(MercuryUtil.createErrorResponse("Forbidden", "Request could not be validated")) .build(); } if (jsonObject.size() != 0) { return Response.status(Status.ACCEPTED).entity(jsonObject).build(); } return Response.status(Status.ACCEPTED).build(); } catch (RuntimeException ex) { LogHelper.error("Encountered an error processing 'checkAuthentication' in '" + getClass().getSimpleName() + "' - " + ex.getMessage()); ex.printStackTrace(); } return Response .status(Status.INTERNAL_SERVER_ERROR).entity(MercuryUtil .createErrorResponse("Internal Server Error", "An error occurred during authentication!")) .build(); }
From source file:org.hibernate.search.backend.elasticsearch.search.sort.impl.FieldSortBuilderImpl.java
License:LGPL
@Override public void doBuildAndAddTo(ElasticsearchSearchSortCollector collector) { JsonObject innerObject = getInnerObject(); if (innerObject.size() == 0) { collector.collectSort(new JsonPrimitive(absoluteFieldPath)); } else {// w ww . j av a 2 s . c o m JsonObject outerObject = new JsonObject(); outerObject.add(absoluteFieldPath, innerObject); collector.collectSort(outerObject); } }
From source file:org.hibernate.search.backend.elasticsearch.search.sort.impl.ScoreSortBuilderImpl.java
License:LGPL
@Override public void doBuildAndAddTo(ElasticsearchSearchSortCollector collector) { JsonObject innerObject = getInnerObject(); if (innerObject.size() == 0) { collector.collectSort(SCORE_SORT_KEYWORD_JSON); } else {/*from www .jav a 2 s .c o m*/ JsonObject outerObject = new JsonObject(); outerObject.add(SCORE_SORT_KEYWORD, innerObject); collector.collectSort(outerObject); } }
From source file:org.qcert.runtime.BinaryOperators.java
License:Apache License
private static boolean compatibleRecs(JsonObject rec1, JsonObject rec2) { if (rec1.size() <= rec2.size()) { return compatibleRecsAux(rec1, rec2); } else {//from w w w .j av a2 s .com return compatibleRecsAux(rec2, rec1); } }
From source file:org.qcert.runtime.DataComparator.java
License:Apache License
public int compare(JsonObject o1, JsonObject o2) { final int sizeCompare = Integer.compare(o1.size(), o2.size()); if (sizeCompare != 0) { return sizeCompare; }/*w w w . j a va 2s .c o m*/ TreeMap<String, JsonElement> map1 = recToTreeMap(o1); TreeMap<String, JsonElement> map2 = recToTreeMap(o2); // it is important for transitivity that the keys are sorted first, // which the TreeMap does for us final int keyComp = compareKeys(map1.keySet().iterator(), map2.keySet().iterator()); if (keyComp != 0) { return keyComp; } else { // they have identical keys } Iterator<Entry<String, JsonElement>> iter1 = map1.entrySet().iterator(); Iterator<Entry<String, JsonElement>> iter2 = map2.entrySet().iterator(); while (iter1.hasNext()) { assert (iter2.hasNext()); Entry<String, JsonElement> entry1 = iter1.next(); Entry<String, JsonElement> entry2 = iter2.next(); assert (entry1.getKey().equals(entry2.getKey())); int elemcomp = this.compare(entry1.getValue(), entry2.getValue()); if (elemcomp != 0) { return elemcomp; } } // if we made it through, then they are equal. return 0; }
From source file:org.qcert.util.SchemaUtil.java
License:Apache License
public static Map<String, ObjectType> getGlobalsFromSchema(JsonObject schema) { /* Deal with possibly different levels of wrapping */ if (schema.has("schema")) schema = schema.get("schema").getAsJsonObject(); if (schema.has("model")) // now obsolete but may persist in some corners schema = schema.get("model").getAsJsonObject(); Map<String, ObjectType> ans = new HashMap<>(); if (schema.has("globals")) { schema = schema.get("globals").getAsJsonObject(); if (schema.size() == 1 && schema.has("WORLD")) // We heuristically assume the globals are uninteresting in the "one WORLD" case. Use getSchema if the important // information is contained in the branded types. return ans; for (Entry<String, JsonElement> member : schema.entrySet()) { String typeName = member.getKey(); JsonObject typeDef = member.getValue().getAsJsonObject().get("type").getAsJsonObject().get("$coll") .getAsJsonObject();// ww w . java 2 s .c o m ans.put(typeName, makeObjectType(typeName, typeDef)); } } return ans; }
From source file:org.tallison.gramreaper.ingest.schema.FieldMapper.java
License:Apache License
public static FieldMapper load(JsonElement el) { if (el == null) { throw new IllegalArgumentException(NAME + " must not be empty"); }//from w ww . j av a2s. c o m JsonObject root = el.getAsJsonObject(); if (root.size() == 0) { return new FieldMapper(); } //build ignore case element JsonElement ignoreCaseElement = root.get(IGNORE_CASE_KEY); if (ignoreCaseElement == null || !ignoreCaseElement.isJsonPrimitive()) { throw new IllegalArgumentException( "ignore case element in field mapper must not be null and must be a primitive: " + ((ignoreCaseElement == null) ? "" : ignoreCaseElement.toString())); } String ignoreCaseString = ((JsonPrimitive) ignoreCaseElement).getAsString().toLowerCase(); FieldMapper mapper = new FieldMapper(); if ("true".equals(ignoreCaseString)) { mapper.setIgnoreCase(true); } else if ("false".equals(ignoreCaseString)) { mapper.setIgnoreCase(false); } else { throw new IllegalArgumentException(IGNORE_CASE_KEY + " must have a value of \"true\" or \"false\""); } JsonArray mappings = root.getAsJsonArray("mappings"); for (JsonElement mappingElement : mappings) { JsonObject mappingObj = mappingElement.getAsJsonObject(); String from = mappingObj.getAsJsonPrimitive("f").getAsString(); IndivFieldMapper indivFieldMapper = buildMapper(mappingObj); mapper.add(from, indivFieldMapper); } return mapper; }
From source file:org.wso2.carbon.apimgt.rest.api.authenticator.AuthenticatorAPI.java
License:Open Source License
/** * This method provides the DCR application information to the SSO-IS login. * * @param request Request to call the /login api * @return Response - Response object with OAuth data *//*from ww w. ja v a 2 s .c o m*/ @OPTIONS @GET @Path("/login/{appName}") @Produces(MediaType.APPLICATION_JSON) public Response redirect(@Context Request request, @PathParam("appName") String appName) { try { AuthenticatorService authenticatorService = AuthenticatorAPIFactory.getInstance().getService(); JsonObject oAuthData = authenticatorService.getAuthenticationConfigurations(appName); if (oAuthData.size() == 0) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity("Error while creating the OAuth application!").build(); } else { return Response.status(Response.Status.OK).entity(oAuthData).build(); } } catch (APIManagementException e) { ErrorDTO errorDTO = AuthUtil.getErrorDTO(e.getErrorHandler(), null); log.error(e.getMessage(), e); return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build(); } }
From source file:org.wso2.extension.siddhi.map.json.sourcemapper.JsonSourceMapper.java
License:Open Source License
private Event[] convertToEventArrayForDefaultMapping(Object eventObject) { Gson gson = new Gson(); JsonObject[] eventObjects = gson.fromJson(eventObject.toString(), JsonObject[].class); Event[] events = new Event[eventObjects.length]; int index = 0; JsonObject eventObj = null; for (JsonObject jsonEvent : eventObjects) { if (jsonEvent.has(DEFAULT_JSON_EVENT_IDENTIFIER)) { eventObj = jsonEvent.get(DEFAULT_JSON_EVENT_IDENTIFIER).getAsJsonObject(); if (failOnMissingAttribute && eventObj.size() < streamAttributes.size()) { log.error("Json message " + eventObj.toString() + " contains missing attributes. " + "Hence dropping the message."); continue; }/*from w w w . j a va 2 s .co m*/ } else { log.error("Default json message " + eventObj.toString() + " in the array does not have the valid event identifier \"event\". " + "Hence dropping the message."); continue; } Event event = new Event(streamAttributes.size()); Object[] data = event.getData(); int position = 0; for (Attribute attribute : streamAttributes) { String attributeName = attribute.getName(); Attribute.Type type = attribute.getType(); String attributeValue = eventObj.get(attributeName).getAsString(); if (attributeValue == null) { data[position++] = null; } else { data[position++] = attributeConverter.getPropertyValue(attributeValue, type); } } events[index++] = event; } return Arrays.copyOfRange(events, 0, index); }