List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.gst.infrastructure.core.serialization.GoogleGsonSerializerHelper.java
License:Apache License
public Gson createGsonBuilderForPartialResponseFiltering(final boolean prettyPrint, final Set<String> responseParameters) { final ExclusionStrategy strategy = new ParameterListInclusionStrategy(responseParameters); final GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy); builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter()); builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter()); builder.registerTypeAdapter(MonthDay.class, new JodaMonthDayAdapter()); if (prettyPrint) { builder.setPrettyPrinting();/*from w w w. j a va2 s .co m*/ } return builder.create(); }
From source file:com.gst.infrastructure.core.serialization.GoogleGsonSerializerHelper.java
License:Apache License
public Gson createGsonBuilderWithParameterExclusionSerializationStrategy(final Set<String> supportedParameters, final boolean prettyPrint, final Set<String> responseParameters) { final Set<String> parameterNamesToSkip = new HashSet<>(); if (!responseParameters.isEmpty()) { // strip out all known support parameters from expected response to // see if unsupported parameters requested for response. final Set<String> differentParametersDetectedSet = new HashSet<>(responseParameters); differentParametersDetectedSet.removeAll(supportedParameters); if (!differentParametersDetectedSet.isEmpty()) { throw new UnsupportedParameterException(new ArrayList<>(differentParametersDetectedSet)); }/*from www. j a va 2 s. c om*/ parameterNamesToSkip.addAll(supportedParameters); parameterNamesToSkip.removeAll(responseParameters); } final ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip); final GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy); builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter()); builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter()); builder.registerTypeAdapter(MonthDay.class, new JodaMonthDayAdapter()); if (prettyPrint) { builder.setPrettyPrinting(); } return builder.create(); }
From source file:com.gullakh.gullakhandroidapp.GoogleCardsMediaActivity.java
License:Apache License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();//from w w w . jav a2 s . c om String data = intent.getStringExtra("data"); bankid_cibil = intent.getStringExtra("bankid"); if (bankid_cibil == null)//first time ..initialize only once { Log.d("bankname_cibil is null", "1"); } else { /*if (savedInstanceState != null) { Log.d("savedInstanceState not null","1"); high_cibil = savedInstanceState.getStringArrayList("cibil_high"); Log.d("high_cibil in oncreate", String.valueOf(high_cibil)); }*/ if (((GlobalData) getApplication()).gethigh_cibil() != null) { high_cibil = ((GlobalData) getApplication()).gethigh_cibil(); Log.d("high_cibil in oncreate", String.valueOf(high_cibil)); } Log.d("bankname_cibil is not null", bankid_cibil); high_cibil.add(bankid_cibil); Log.d("bankname_cibil is in goog", String.valueOf(high_cibil)); } //********************changing actionbar android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowCustomEnabled(true); LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.custom_actionbar_eachactivity, null); title = (TextView) v.findViewById(R.id.title); ImageView review = (ImageView) v.findViewById(R.id.edit); review.setVisibility(View.GONE); ImageView close = (ImageView) v.findViewById(R.id.close); close.setOnClickListener(this); actionBar.setCustomView(v); View v2 = getSupportActionBar().getCustomView(); ViewGroup.LayoutParams lp = v2.getLayoutParams(); lp.width = AbsListView.LayoutParams.MATCH_PARENT; v2.setLayoutParams(lp); //****************************************** DataHandler dbobjectsess = new DataHandler(GoogleCardsMediaActivity.this); Cursor crsess = dbobjectsess.displayData("select * from session"); if (crsess.moveToFirst()) { sessionid = crsess.getString(1); Log.e("sessionid-cartypes", sessionid); } age = ((GlobalData) getApplication()).getage(); if (data.equals("searchgo")) { Log.e("flow test carloan", String.valueOf(0)); loan_amtcalcutn("oncreate"); Log.e("flow test loan cal done", String.valueOf(CustomListViewValuesArr.size())); setContentView(R.layout.list_display); //ListView listView = (ListView) findViewById(R.id.list_view); layout = (LinearLayout) findViewById(R.id.linear); linedit = (LinearLayout) findViewById(R.id.linedit); filter = (LinearLayout) findViewById(R.id.filter); // lcomp = (LinearLayout) findViewById(R.id.lcomp); loan_amt = (TextView) findViewById(R.id.loan_amt); tenr_amt = (TextView) findViewById(R.id.tenr_amt); tten = (TextView) findViewById(R.id.tenure); TextView tloan_amt = (TextView) findViewById(R.id.tloan_amt); TextView tfilter = (TextView) findViewById(R.id.tfilter); /*loan_amt.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf")); tloan_amt.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf")); tfilter.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf")); tenr_amt.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf")); tten.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf"));*/ linedit.setOnClickListener(this); filter.setOnClickListener(this); // lcomp.setOnClickListener(this); // createListView(); format = NumberFormat.getCurrencyInstance(new Locale("en", "in")); //nullpointer if (savedInstanceState != null) { Log.d("savedInstanceState not null", "1"); loant = String.valueOf(format.format(new BigDecimal(savedInstanceState.getString("loan_amt")))); loant = loant.replaceAll("\\.00", ""); loan = savedInstanceState.getString("loan_amt"); globaltenure = savedInstanceState.getString("tenure"); globalloan_type = savedInstanceState.getString("loan_type"); globalsal = savedInstanceState.getString("net_sal"); } else { loan = ((GlobalData) getApplication()).getloanamt(); // Log.d("loan amt is", loan); globaltenure = ((GlobalData) getApplication()).getTenure(); globalloan_type = ((GlobalData) getApplication()).getLoanType(); globalsal = ((GlobalData) getApplication()).getnetsalary().toString(); } if (loan != null) { loant = String.valueOf(format.format(new BigDecimal(loan))); loant = loant.replaceAll("\\.00", ""); Log.d("loan amt is not null", loant); // loan = loan.replaceAll("Rs.", ""); } loan_amt.setText("" + loant); filter.setOnClickListener(this); createListView(); Spinner s1 = (Spinner) findViewById(R.id.spinner1); MyArrayAdapter ma = new MyArrayAdapter(this); s1.setAdapter(ma); s1.setPrompt("Sort By"); // if(globalloan_type.equals("Home Loan") || globalloan_type.equals("Loan Against Property")) if (globalloan_type.equals("Home Loan")) { Log.d("its home or LAP -", globalloan_type); f_fixed = false; f_float = true; } //******get data from search // setsearchdb(); s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { sortbyposition = position; Log.d("test position", String.valueOf(position)); if (position != 0) calculate(); setadapter(CustomListViewValuesArr); } public void onNothingSelected(AdapterView<?> parent) { } }); } else if (data.equals("search")) { DataHandler dbobject = new DataHandler(GoogleCardsMediaActivity.this); Cursor crobj = dbobject.displayData("select * from userlogin"); if (crobj.moveToFirst()) { Log.d("my search clicked", "2"); setContentView(R.layout.seach_display); layout = (LinearLayout) findViewById(R.id.linear); setsearchdb(); createListView(); setsearchadapter(searchlistviewArry); } else { Toast.makeText(GoogleCardsMediaActivity.this, "Please login to view search details!!!", Toast.LENGTH_LONG).show(); title.setText("Search Result"); } } /*Log.e("You are not logged in", String.valueOf(0)); Intent intentsignin=new Intent(this,signinPrepage.class); startActivity(intentsignin); finish();*/ if (data.equals("myapplicatn")) { DataHandler dbobject = new DataHandler(GoogleCardsMediaActivity.this); Cursor crobj = dbobject.displayData("select * from userlogin"); title.setText("My Applications"); if (crobj.moveToFirst()) { // DataHandler dh1 = new DataHandler(this); // Cursor cr = dh1.displayData("select * from mysearch"); try { // if (cr.moveToFirst()) { requestgetserver8 = new JSONServerGet(new AsyncResponse() { @Override public void processFinish(JSONObject output) { } public void processFinishString(String str_result, Dialog dg) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("M/d/yy hh:mm a"); Gson gson = gsonBuilder.create(); dgthis = dg; JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(str_result).getAsJsonObject(); Log.d("checkloandetail", String.valueOf(jsonObject.get("result"))); JsonObject jsonObject1 = parser.parse(String.valueOf(jsonObject.get("result"))) .getAsJsonObject(); LoanReqForMyapp[] loanDeatils = gson.fromJson(jsonObject1.get("loanrequest"), LoanReqForMyapp[].class); //JsonArray jsonArr = jsonObject1.getAsJsonArray("loanrequest"); if (loanDeatils.length > 0) { for (int i = 0; i < loanDeatils.length; i++) { //JsonObject jsonObject2 = jsonArr.get(i).getAsJsonObject(); //LoanReqForMyapp loanDeatils = gson.fromJson(jsonObject2, LoanReqForMyapp.class);// LoanReqForMyapp[] loandetailsobj = gson.fromJson(jsonObject2, LoanReqForMyapp[].class); if (loanDeatils[i] != null) { Log.d("here is data", loanDeatils[i].getLoan_amount()); ListModel sched = new ListModel(); sched.setapplno(loanDeatils[i].case_loan_number);//data is present in listmodel class variables,values are put inside listmodel class variables, accessed in CustHotel class put in list here sched.setappldate(loanDeatils[i].getCreatedtime()); sched.setstatus(loanDeatils[i].getStage()); sched.setLoancaseid(loanDeatils[i].getLoanrequestcaseid()); sched.setContactid(String.valueOf(jsonObject1.get("contactid"))); sched.setD0(loanDeatils[i].getD0()); sched.setD1(loanDeatils[i].getD1()); sched.setD2(loanDeatils[i].getD2()); sched.setD3(loanDeatils[i].getD3()); sched.setD4(loanDeatils[i].getD4()); sched.setD5(loanDeatils[i].getD5()); sched.setD6(loanDeatils[i].getD6()); sched.setD7(loanDeatils[i].getD7()); sched.setD8(loanDeatils[i].getD8()); sched.setCompletedpercentage(loanDeatils[i].getCompletedpercentage()); sched.setLoan_amount(loanDeatils[i].getLoan_amount()); sched.setBank_name(loanDeatils[i].getPrimary_lender()); sched.setLoan_type(loanDeatils[i].getLoantype()); sched.setPlemi(loanDeatils[i].getPlemi()); sched.setPlroi(loanDeatils[i].getPlroi()); sched.setdoc_collect_by(loanDeatils[i].getdoc_collect_by()); searchlistviewArry.add(sched); } } setContentView(R.layout.seach_display); layout = (LinearLayout) findViewById(R.id.linear); createListView(); setapplicatnadapter(searchlistviewArry); } else { AlertDialog.Builder alertadd = new AlertDialog.Builder( GoogleCardsMediaActivity.this); LayoutInflater factory = LayoutInflater.from(getApplicationContext()); final View view = factory.inflate(R.layout.applnotfound, null); TextView name = (TextView) view.findViewById(R.id.nf); name.setText("No Application Found"); alertadd.setView(view); alertadd.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent(GoogleCardsMediaActivity.this, MainActivity.class); intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); overridePendingTransition(R.transition.left, R.transition.right); } }); alertadd.show(); } dgthis.dismiss(); } }, GoogleCardsMediaActivity.this, "wait"); DataHandler dbobj = new DataHandler(GoogleCardsMediaActivity.this); Cursor cre = dbobj.displayData("select * from userlogin"); String userid = "", contactid = ""; if (cre != null) { if (cre.moveToFirst()) { userid = cre.getString(1); contactid = cre.getString(2); Log.d("userid myapp", userid); Log.d("contactid myapp", contactid); cre.close(); dbobject.close(); } } requestgetserver8.execute("token", "getloandetails", sessionid, contactid); // } } catch (Exception e) { System.out.println("error3 " + e.toString()); // dh1.cr.close(); // dh1.db.close(); } finally { // dh1.cr.close(); // dh1.db.close(); } } else { Toast.makeText(GoogleCardsMediaActivity.this, "Please login to view application details!!!", Toast.LENGTH_LONG).show(); } } //****** //format df = new DecimalFormat("#,##,###"); // df.setDecimalSeparatorAlwaysShown(true); }
From source file:com.gullakh.gullakhandroidapp.GoogleCardsMediaActivity.java
License:Apache License
public void loan_amtcalcutn(final String param) { //phase -2//ww w.j a v a2 s. c om requestgetserver2 = new JSONServerGet(new AsyncResponse() { @Override public void processFinish(JSONObject output) { } public void processFinishString(String str_result, Dialog dg) { try { Log.e("processFinishString in image", String.valueOf(0)); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("M/d/yy hh:mm a"); Gson gson = gsonBuilder.create(); JSONObject jsonObject = new JSONObject(str_result); Log.e("Check result in servicecharge", String.valueOf(jsonObject)); Log.e("Check result in servicecharge", String.valueOf(jsonObject.get("result"))); JSONObject jsonObject2 = new JSONObject(String.valueOf(jsonObject.get("result"))); procegn_fee_perc = jsonObject2.getString("percentage"); Log.e("Check result in servicecharge percentage", procegn_fee_perc); } catch (Throwable t) { Log.e("My App", "Could not parse malformed JSON: "); } } }, GoogleCardsMediaActivity.this, "2"); //******* requestgetserver2.execute("sessn", "servicecharge", sessionid); requestgetserver3 = new JSONServerGet(new AsyncResponse() { @Override public void processFinish(JSONObject output) { } public void processFinishString(String str_result, Dialog dg) { dgthis = dg; GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("M/d/yy hh:mm a"); Gson gson = gsonBuilder.create(); JsonParser parser = new JsonParser(); if (parser.parse(str_result).getAsJsonObject() != null) { JsonObject jsonObject = parser.parse(str_result).getAsJsonObject(); Log.e("Check final data here3", str_result); //****cibilscore int maxLogSize = 2000; for (int i = 0; i <= str_result.length() / maxLogSize; i++) { int start = i * maxLogSize; int end = (i + 1) * maxLogSize; end = end > str_result.length() ? str_result.length() : end; Log.v("CHECK111", str_result.substring(start, end)); } /* if(bankid_cibil!=null) { JSONArray resultarry = new JSONArray(); resultarry.put(parse(str_result)); try { // Log.d("bankid_cibil is not null cibil", String.valueOf(resultarry.getJSONArray(0))); Log.d("bankid_cibil is not null cibil", String.valueOf(resultarry.get(0))); RM_cobj = gson.fromJson(String.valueOf(resultarry.get(0)), RuleMaster[].class); } catch (JSONException e) { e.printStackTrace(); } } else { RM_cobj = gson.fromJson(jsonObject.get("result"), RuleMaster[].class); }*/ RuleMaster[] RM_cobj = gson.fromJson(jsonObject.get("result"), RuleMaster[].class); ArrayList Arr_RMid = new ArrayList<String>(); JSONArray jsonArray = new JSONArray(); //***********high cibil //*********** if (RM_cobj != null) { for (int i = 0; i < RM_cobj.length; i++) { JSONObject imgob = new JSONObject(); Log.e("json Sizeee in RM_cobj", String.valueOf(RM_cobj.length)); Log.e("RM_cobj is ", String.valueOf(RM_cobj[i])); Arr_RMid.add(RM_cobj[i].getaccount_lender()); try { imgob.put("recordid", RM_cobj[i].getaccount_lender()); imgob.put("title", "logo"); jsonArray.put(imgob); } catch (JSONException e) { e.printStackTrace(); } Log.e("json Checkkk", String.valueOf(jsonArray)); } if (bankid_cibil != null) { for (int i2 = 0; i2 < high_cibil.size(); i2++) { Arr_RMid.remove(high_cibil.get(i2)); Log.e("high_cibil.get(i2)", high_cibil.get(i2)); for (int i = 0; i < jsonArray.length(); i++) { JSONObject actor = null; try { actor = jsonArray.getJSONObject(i); String name = actor.getString("recordid"); if (name.equals(high_cibil.get(i2))) { Log.e("jsonArray recordid", name); jsonArray.remove(i); } } catch (JSONException e) { e.printStackTrace(); } } } Log.e("Arr_RMid", String.valueOf(Arr_RMid)); } Log.e("json object value KK", String.valueOf(jsonArray)); cobj_RM = RM_cobj; listidmaster = Arr_RMid.toString(); //Log.e("listid2", listid); listidmaster = listidmaster.toString().replace("[", "").replace("]", ""); requestgetserver3img.execute("token", "accountimg", sessionid, jsonArray.toString()); } else { dispalert(""); } //******************kk } else { dispalert(""); } } }, GoogleCardsMediaActivity.this, "1"); requestgetserver3.execute("sessn", "RuleDetails"); requestgetserver3img = new JSONServerGet(new AsyncResponse() { @Override public void processFinish(JSONObject output) { } public void processFinishString(String str_result, Dialog dg) { try { Log.e("processFinishString in image", String.valueOf(0)); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("M/d/yy hh:mm a"); Gson gson = gsonBuilder.create(); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(str_result).getAsJsonObject(); Log.e("Check result in image", str_result); BankImg[] BL_cobj = gson.fromJson(jsonObject.get("result"), BankImg[].class); Arry_bankimg = new HashMap<>(); for (int i = 0; i < BL_cobj.length; i++) { Arry_bankimg.put(BL_cobj[i].getaccountid(), BL_cobj[i].geturl()); } Log.e("Check final Arry_bankimg", String.valueOf(Arry_bankimg)); requestgetserver4.execute("token", "accountname", sessionid, listidmaster); } catch (Throwable t) { Log.e("My App", "Could not parse malformed JSON: "); } } }, GoogleCardsMediaActivity.this, "2"); requestgetserver4 = new JSONServerGet(new AsyncResponse() { @Override public void processFinish(JSONObject output) { } public void processFinishString(String str_result, Dialog dg) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("M/d/yy hh:mm a"); Gson gson = gsonBuilder.create(); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(str_result).getAsJsonObject(); Log.e("Check final data here3", str_result); dgthis.dismiss(); BankList[] BL_cobj = gson.fromJson(jsonObject.get("result"), BankList[].class); Map<String, String> Arry_banknamtemp = new HashMap<>(); for (int i = 0; i < BL_cobj.length; i++) { Arry_banknamtemp.put(BL_cobj[i].getid(), BL_cobj[i].getaccountname()); } Arry_banknam = Arry_banknamtemp; net_salry = Double.parseDouble(globalsal); //*cal tenure here String typ_loan = globalloan_type; Log.d("tenure loantyp", typ_loan); /* if (typ_loan.equals("Car Loan")) { //calTenure(7,5); calTenure(7); } else if (typ_loan.equals("Home Loan")) { calTenure(30); } else if (typ_loan.equals("Loan Against Property")) { calTenure(30); } else if (typ_loan.equals("Personal Loan")) { calTenure(5); //calTenure(5, 15); }*/ if (((GlobalData) getApplication()).getemptype().equals("Salaried")) calTenure(60); else calTenure(65); emi = ((GlobalData) getApplication()).getEmi().intValue(); disbank = new ArrayList<String>(); calculate();//here will get bank to be displayed i.e CustomListViewValuesArr Log.e("flow test", String.valueOf(CustomListViewValuesArr.size())); if (CustomListViewValuesArr.size() == 0 || Max_tenure == 0) { Log.d("CustomListViewValuesArr.size()", String.valueOf(CustomListViewValuesArr.size())); Log.d("Max_tenure val", String.valueOf(Max_tenure)); AlertDialog.Builder builder = new AlertDialog.Builder(GoogleCardsMediaActivity.this); // builder.setMessage("Sorry, there were no Loan Offers matching your criteria!!!") maxbp = maxbp - (maxbp % 1000); maxbpval = (int) maxbp; Log.d("reduced loan to server2", String.valueOf(Math.ceil(maxbpval))); builder.setMessage("You are eligible for Rs " + maxbpval + " amount only.").setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ((GlobalData) getApplication()).setloanamt(String.valueOf(maxbpval)); loan_amtcalcutn("oncreate"); loan_amt.setText(maxbpval + ""); /*Intent intent = new Intent(getApplicationContext(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent);*/ } }); AlertDialog alert = builder.create(); alert.show(); } else { // Log.d("disbank", String.valueOf(disbank)); if (param.equals("oncreate")) setadapter(CustomListViewValuesArr); Log.e("flow test", String.valueOf(1)); } } }, GoogleCardsMediaActivity.this, "3"); ServerConnect cls2 = new ServerConnect(); if (((GlobalData) getApplication()).getcarres() != null) { Log.d("checking city name here", ((GlobalData) getApplication()).getcarres()); // requestgetserver6.execute("token", "City", sessionid, ((GlobalData) getApplication()).getcarres()); } // requestgetserver5.execute("token", "LoanType", sessionid); Log.e("flow test", String.valueOf(3)); prgmImages = new int[] { R.drawable.icici_bank_logo2, R.drawable.axisbank_logo, R.drawable.bankofindia_logo, R.drawable.hdfcbank_logo, R.drawable.hdfcbank_logo, R.drawable.hdfcbank_logo }; prevloan = 0; }
From source file:com.hackerati.android.user_sdk.gson.HGsonBuilder.java
License:Open Source License
public static final Gson create() { final GsonBuilder builder = new GsonBuilder(); builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); return builder.create(); }
From source file:com.hacksurfer.api.client.RunIndustryRiskScoreExample.java
License:Open Source License
public static void main(String args[]) throws Exception { LOG.info("Running example HTTP GET against HackSurfer Industry Risk Scores /yesterday resource."); SimpleRestClient client = new SimpleRestClient(); String response = client.httpGet(API_BASE_URL, IRS_YESTERDAY_RESOURCE_PATH); // print response LOG.info("Response from /yesterday resource : {}", response); // do something useful with it GsonBuilder gb = new GsonBuilder(); gb.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); Gson gson = gb.create(); List<IndustryRiskScore> scores = gson.fromJson(response, new TypeToken<List<IndustryRiskScore>>() { }.getType());/*from w w w .j a v a 2 s .com*/ LOG.info("Found {} industry risk scores from yesterday.", scores.size()); for (IndustryRiskScore irs : scores) { StringBuilder sb = new StringBuilder(); sb.append(System.lineSeparator()); sb.append("Industry : "); sb.append(irs.getIndustryDescription()); sb.append(System.lineSeparator()); sb.append(" id : "); sb.append(irs.getIndustryId()); sb.append(System.lineSeparator()); sb.append(" risk : "); sb.append(irs.getIndustryGravity()); sb.append(System.lineSeparator()); sb.append(" gravity : "); sb.append(irs.getIndustryRisk()); sb.append(System.lineSeparator()); sb.append(" momentum : "); sb.append(irs.getIndustryMomentum()); sb.append(System.lineSeparator()); System.out.println(sb.toString()); } LOG.info("Well that was fun!"); }
From source file:com.hagreve.android.lib.HaGreveApi.java
License:Apache License
/** * Obtains the list of current strikes./* ww w.j a va2 s .co m*/ * @return Array of Strike objects */ public static Strike[] getStrikes() { Strike[] items = new Strike[0]; String result = doGetRequest(BASE_URL + "/strikes"); if (result != null) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { return formatter.parse(json.getAsString()); } catch (ParseException e) { throw new JsonParseException(e.getMessage()); } } }); Gson gson = builder.create(); items = gson.fromJson(result, Strike[].class); } return items; }
From source file:com.haulmont.cuba.core.app.serialization.EntitySerialization.java
License:Apache License
protected Gson createGsonForSerialization(@Nullable View view, EntitySerializationOption... options) { GsonBuilder gsonBuilder = new GsonBuilder(); if (ArrayUtils.contains(options, EntitySerializationOption.PRETTY_PRINT)) { gsonBuilder.setPrettyPrinting(); }//from www.j a v a2s . co m gsonBuilder.registerTypeHierarchyAdapter(Entity.class, new EntitySerializer(view, options)) .registerTypeHierarchyAdapter(Date.class, new DateSerializer()).create(); if (ArrayUtils.contains(options, EntitySerializationOption.SERIALIZE_NULLS)) { gsonBuilder.serializeNulls(); } return gsonBuilder.create(); }
From source file:com.hbm.devices.scan.announce.AnnounceDeserializer.java
License:Open Source License
/** * Constructs a {@link AnnounceDeserializer} object. *//* ww w . j a va 2 s . c o m*/ public AnnounceDeserializer() { super(); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(JsonRpc.class, new JsonRpcDeserializer()); builder.registerTypeAdapter(AnnounceParams.class, new AnnounceParamsDeserializer()); Type serviceListType = new TypeToken<List<ServiceEntry>>() { }.getType(); builder.registerTypeAdapter(serviceListType, new ServiceDeserializer()); builder.registerTypeAdapter(Interface.class, new InterfaceDeserializer()); // builder.registerTypeAdapter(IPEntry.class, new IPv4Deserializer()); gson = builder.create(); this.announceCache = new AnnounceCache(); }
From source file:com.hbm.devices.scan.configure.ResponseDeserializer.java
License:Open Source License
/** * Constructs a {@link ResponseDeserializer} object. *///from w w w .ja v a 2 s . c o m public ResponseDeserializer() { super(); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(JsonRpc.class, new JsonRpcDeserializer()); gson = builder.create(); }