List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject()
From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java
License:Apache License
public LocalDate extractLocalDateNamed(final String parameterName, final JsonObject element, final String dateFormat, final Locale clientApplicationLocale, final Set<String> parametersPassedInCommand) { LocalDate value = null;/* w ww .j av a 2s . c o m*/ if (element.isJsonObject()) { final JsonObject object = element.getAsJsonObject(); if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) { parametersPassedInCommand.add(parameterName); final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive(); final String valueAsString = primitive.getAsString(); if (StringUtils.isNotBlank(valueAsString)) { value = convertFrom(valueAsString, parameterName, dateFormat, clientApplicationLocale); } } } return value; }
From source file:com.ibm.watson.apis.conversation_enhanced.rest.SetupResource.java
License:Open Source License
/** * Method to fetch config JSON object and also the workspace_id. * //from w w w. ja va 2 s. co m * @return response */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getConfig() { String workspace_id = System.getenv(Constants.WORKSPACE_ID); //$NON-NLS-1$ logger.debug(MessageFormat.format(Messages.getString("SetupResource.WORKSPACE_ID_IS"), workspace_id)); JsonObject config = new JsonObject(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_STEP, "0"); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.ERROR_CHECK_LOGS")); //$NON-NLS-1$ //$NON-NLS-2$ // Fetch the updated config JSON object from the servlet listener config = new ServletContextListener().getJsonConfig(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug(Messages.getString("SetupResource.CONFIG_STATUS") + config); // The following checks for the workspace_id after the Retrieve and // Rank service is ready for the user. This is done so that when the initial setup is being // done, the user can setup the Conversation service Workspace and provide it's id. if (config.get(Constants.SETUP_STEP).getAsInt() == 3 && config.get(Constants.SETUP_STATE).getAsString().equalsIgnoreCase(Constants.READY)) { if (StringUtils.isNotBlank(workspace_id)) { config.addProperty(Constants.WORKSPACE_ID, workspace_id); //$NON-NLS-1$ } else { config.addProperty(Constants.SETUP_STEP, "0"); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.WORKSPACE_ID_ERROR")); //$NON-NLS-1$ //$NON-NLS-2$ } } return Response.ok(config.getAsJsonObject().toString().trim()).type(MediaType.APPLICATION_JSON) .header("Cache-Control", "no-cache").build(); }
From source file:com.ibm.watson.apis.conversation_with_discovery.rest.SetupResource.java
License:Open Source License
/** * Method to fetch config JSON object and also the workspace_id. * * @return response/*from www . j a va 2 s.c o m*/ */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getConfig() { String workspaceId = System.getenv(Constants.WORKSPACE_ID); logger.debug(MessageFormat.format(Messages.getString("SetupResource.WORKSPACE_ID_IS"), workspaceId)); JsonObject config = new JsonObject(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); config.addProperty(Constants.SETUP_STEP, "0"); config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.CHECK_LOGS")); // Fetch the updated config JSON object from the servlet listener config = new AppServletContextListener().getJsonConfig(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); logger.debug(Messages.getString("SetupResource.CONFIG_STATUS") + config); config.addProperty(Constants.WORKSPACE_ID, workspaceId); if (config.has(Constants.SETUP_STEP) && (config.get(Constants.SETUP_STEP).getAsInt() == 3) && config.get(Constants.SETUP_STATE).getAsString().equalsIgnoreCase(Constants.READY)) { if (StringUtils.isBlank(workspaceId)) { config.addProperty(Constants.SETUP_STEP, "0"); config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.WORKSPACE_ID_ERROR")); } } return Response.ok(config.getAsJsonObject().toString().trim()).type(MediaType.APPLICATION_JSON) .header("Cache-Control", "no-cache").build(); }
From source file:com.kyloth.serleena.synchronization.kylothcloud.RasterDataEntityDeserializer.java
License:Open Source License
@Override public RasterDataEntity deserialize(JsonElement json, Type typeOfR, JsonDeserializationContext context) throws JsonParseException { RasterDataEntity res = new RasterDataEntity(); JsonObject boundingRect = json.getAsJsonObject().get("boundingRect").getAsJsonObject(); final float nwLatitude = boundingRect.getAsJsonObject().get("topLeft").getAsJsonObject().get("latitude") .getAsFloat();//from w w w. j a v a 2 s .c o m final float nwLongitude = boundingRect.getAsJsonObject().get("topLeft").getAsJsonObject().get("longitude") .getAsFloat(); final float seLatitude = boundingRect.getAsJsonObject().get("bottomRight").getAsJsonObject().get("latitude") .getAsFloat(); final float seLongitude = boundingRect.getAsJsonObject().get("bottomRight").getAsJsonObject() .get("longitude").getAsFloat(); res.boundingRect = new Region(new GeoPoint(nwLatitude, nwLongitude), new GeoPoint(seLatitude, seLongitude)); res.base64Raster = json.getAsJsonObject().get("image").getAsString(); return res; }
From source file:com.kyloth.serleena.synchronization.kylothcloud.WeatherEntityDeserializer.java
License:Open Source License
@Override public WeatherDataEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { WeatherDataEntity we = new WeatherDataEntity(); we.morning = parseForecast(json.getAsJsonObject().get("morning")); we.afternoon = parseForecast(json.getAsJsonObject().get("afternoon")); we.night = parseForecast(json.getAsJsonObject().get("night")); we.date = json.getAsJsonObject().get("time").getAsLong(); JsonObject boundingRect = json.getAsJsonObject().get("boundingRect").getAsJsonObject(); final float nwLatitude = boundingRect.getAsJsonObject().get("topLeft").getAsJsonObject().get("latitude") .getAsFloat();/*w w w .j a va2 s . c o m*/ final float nwLongitude = boundingRect.getAsJsonObject().get("topLeft").getAsJsonObject().get("longitude") .getAsFloat(); final float seLatitude = boundingRect.getAsJsonObject().get("bottomRight").getAsJsonObject().get("latitude") .getAsFloat(); final float seLongitude = boundingRect.getAsJsonObject().get("bottomRight").getAsJsonObject() .get("longitude").getAsFloat(); we.boundingRect = new Region(new GeoPoint(nwLatitude, nwLongitude), new GeoPoint(seLatitude, seLongitude)); return we; }
From source file:com.mksingh.camfone.Pinlock.ConfirmPinActivity.java
License:Apache License
private void LoginWithPin(String pin) { dialogManager.showProcessDialog(this, ""); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("method", AppConstants.CUSTOMER_APIS.LOGINPIN); jsonObject.addProperty("email_id", AppPreferences.getUserEmailid(ConfirmPinActivity.this)); jsonObject.addProperty("loginPin", pin); JsonArray jsonArray = new JsonArray(); JsonElement jsonElement = jsonObject.getAsJsonObject(); jsonArray.add(jsonElement);/*w w w . j a va2s . co m*/ com.mksingh.camfone.Utils.Log.d("Request pinlogin", jsonArray.getAsJsonArray() + ""); ApiEndpointInterface apiInterface = ApiClient.getClient(this, "").create(ApiEndpointInterface.class); Call<JsonObject> call1 = apiInterface.customerApi(jsonArray); call1.enqueue(new Callback<JsonObject>() { @Override public void onResponse(Call<JsonObject> call, Response<JsonObject> response) { com.mksingh.camfone.Utils.Log.d("Response pinlogin>>", response.body().toString()); if (response.body().get("status").getAsString().equalsIgnoreCase("200")) { //String userId = response.body().getAsJsonObject("result").get("user_id").getAsString(); //AppPreferences.setUserid(ConfirmPinActivity.this, userId); //startActivity(new Intent(ConfirmPinActivity.this, HomeActivity.class)); setResult(SUCCESS); finish(); } else { Toast.makeText(ConfirmPinActivity.this, response.body().get("message").getAsString(), Toast.LENGTH_LONG).show(); } dialogManager.stopProcessDialog(); } @Override public void onFailure(Call call, Throwable t) { t.printStackTrace(); com.mksingh.camfone.Utils.Log.d("onFailure", call.toString() + "\n" + t.getMessage()); dialogManager.stopProcessDialog(); } }); }
From source file:com.mksingh.meg.Pinlock.ConfirmPinActivity.java
License:Apache License
private void LoginWithPin(String pin) { dialogManager.showProcessDialog(this, ""); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("method", AppConstants.CUSTOMER_APIS.LOGINPIN); jsonObject.addProperty("email_id", AppPreferences.getUserEmailid(ConfirmPinActivity.this)); jsonObject.addProperty("loginPin", pin); JsonArray jsonArray = new JsonArray(); JsonElement jsonElement = jsonObject.getAsJsonObject(); jsonArray.add(jsonElement);// w w w.jav a 2 s.c o m com.mksingh.meg.Utils.Log.d("Request pinlogin", jsonArray.getAsJsonArray() + ""); ApiEndpointInterface apiInterface = ApiClient.getClient(this, "").create(ApiEndpointInterface.class); Call<JsonObject> call1 = apiInterface.customerApi(jsonArray); call1.enqueue(new Callback<JsonObject>() { @Override public void onResponse(Call<JsonObject> call, Response<JsonObject> response) { com.mksingh.meg.Utils.Log.d("Response pinlogin>>", response.body().toString()); if (response.body().get("status").getAsString().equalsIgnoreCase("200")) { //String userId = response.body().getAsJsonObject("result").get("user_id").getAsString(); //AppPreferences.setUserid(ConfirmPinActivity.this, userId); //startActivity(new Intent(ConfirmPinActivity.this, HomeActivity.class)); setResult(SUCCESS); finish(); } else { Toast.makeText(ConfirmPinActivity.this, response.body().get("message").getAsString(), Toast.LENGTH_LONG).show(); } dialogManager.stopProcessDialog(); } @Override public void onFailure(Call call, Throwable t) { t.printStackTrace(); com.mksingh.meg.Utils.Log.d("onFailure", call.toString() + "\n" + t.getMessage()); dialogManager.stopProcessDialog(); } }); }
From source file:com.simonmacdonald.muzei.comic.ComicCoverArtSource.java
License:Open Source License
private Volume fetchVolume(int id) { String strUrl = "http://www.comicvine.com/api/volume/4050-" + id + "/?api_key=" + API.COMICVINE_KEY + "&format=json&field_list=first_issue,last_issue,name"; JsonObject obj = makeComicVineApiRequest(strUrl); int firstIssue = obj.getAsJsonObject("results").getAsJsonObject().getAsJsonObject("first_issue") .getAsJsonObject().getAsJsonPrimitive("issue_number").getAsInt(); int lastIssue = obj.getAsJsonObject("results").getAsJsonObject().getAsJsonObject("last_issue") .getAsJsonObject().getAsJsonPrimitive("issue_number").getAsInt(); return new Volume(id, firstIssue, lastIssue); }
From source file:com.smart.taxi.entities.CorporateInfo.java
public static CorporateInfo deserializeFromJson(JsonObject info) { CorporateInfo ci = new CorporateInfo(); JsonObject rootObj = info.getAsJsonObject(); ci.setId(JsonHelper.getInt(rootObj, "id")); ci.setName(JsonHelper.getString(rootObj, "name")); ci.setAddress(JsonHelper.getString(rootObj, "address")); ci.setEmail(JsonHelper.getString(rootObj, "email")); ci.setPhone_no(JsonHelper.getString(rootObj, "phone_no")); ci.setLicenseNo(JsonHelper.getString(rootObj, "license_no")); return ci;/*from w w w. ja v a 2 s.c o m*/ }
From source file:com.smart.taxi.entities.Journey.java
public JsonObject ignoreNestedObject(JsonObject parentjsonObject, String parentKey) { String mainJson = parentjsonObject.getAsJsonObject(parentKey).getAsJsonObject().entrySet().iterator().next() .getValue().toString();/*w w w. j a v a 2s .com*/ return JsonHelper.parseToJsonObject(mainJson); }