List of usage examples for com.google.gson GsonBuilder setPrettyPrinting
public GsonBuilder setPrettyPrinting()
From source file:TestingAPP.Main.java
public String CrearMensaje(String ptitle, String pisbn10, String pisbn13, String[] pauthors) { final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Book.class, new BookSerialiser()); gsonBuilder.setPrettyPrinting(); final Gson gson = gsonBuilder.create(); final Book javaPuzzlers = new Book(); javaPuzzlers.setTitle(ptitle);//w ww . j ava 2 s .c o m javaPuzzlers.setIsbn10(pisbn10); javaPuzzlers.setIsbn13(pisbn13); javaPuzzlers.setAuthors(pauthors); // Format to JSON final String json = gson.toJson(javaPuzzlers); return json; }
From source file:ua.pp.msk.cliqr.job.JobRunInit.java
License:Apache License
public String toJson() { GsonBuilder gb = new GsonBuilder(); gb.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY); gb.setPrettyPrinting(); Gson gson = gb.create();//from w w w. j a v a2 s .c o m String toJson = gson.toJson(this); return toJson; }
From source file:ua.pp.msk.cliqr.JobInfoImpl.java
License:Apache License
@Override public void getJobInfo(JobFilter... filters) throws MalformedURLException, ClientSslException, ResponseException { ParsedJob[] jobs = getJobList().getJobs(); for (JobFilter jf : filters) { jobs = jf.filter(jobs);//from w w w. j av a 2s . c o m } JobList jobList = new JobList(); jobList.setJobs(jobs); jobList.setSize(jobs.length); GsonBuilder gbuilder = new GsonBuilder(); gbuilder.setPrettyPrinting(); gbuilder.registerTypeAdapter(ParsedJob.class, new ParsedJob.JobSerializer()); gbuilder.registerTypeAdapter(JobList.class, new JobList.JobListSerializer()); Gson gson = gbuilder.create(); gson.toJson(jobList, ops); }
From source file:unl.cse.DataConvert.java
/** * <i>parsePersonsJson</i> will generate an JSON file using the parsed * data from the old system./*from ww w . j a v a2s . c o m*/ * * @param jsonOut - If true, the JSON file will be displayed in the console */ private void parsePersonsJson(boolean jsonOut) { System.out.println("Generating JSON file: " + PERSONS_JSON_FILE + "\n"); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting().disableHtmlEscaping(); Gson gson = gsonBuilder.create(); String json = gson.toJson(phub); if (jsonOut == true) { System.out.println(json); } FileWriter f = null; try { f = new FileWriter(PERSONS_JSON_FILE); f.write(json); f.flush(); f.close(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:unl.cse.DataConvert.java
/** * <i>parseCustomersJson</i> will generate an JSON file using the parsed * data from the old system.//from w w w .ja v a2 s . c o m * * @param jsonOut - If true, the JSON file will be displayed in the console */ public void parseCustomersJson(boolean jsonOut) { System.out.println("Generating JSON file: " + CUSTOMERS_JSON_FILE + "\n"); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting().disableHtmlEscaping(); Gson gson = gsonBuilder.create(); String json = gson.toJson(chub); if (jsonOut == true) { System.out.println(json); } FileWriter f = null; try { f = new FileWriter(CUSTOMERS_JSON_FILE); f.write(json); f.flush(); f.close(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:unl.cse.DataConvert.java
/** * <i>parseProductsJson</i> will generate an JSON file using the parsed * data from the old system./* www. j a v a2s. c o m*/ * * @param jsonOut - If true, the JSON file will be displayed in the console */ public void parseProductsJson(boolean jsonOut) { System.out.println("Generating JSON file: " + PERSONS_JSON_FILE + "\n"); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting().disableHtmlEscaping(); Gson gson = gsonBuilder.create(); String json = gson.toJson(prhub); if (jsonOut == true) { System.out.println(json); } FileWriter f = null; try { f = new FileWriter(PRODUCTS_JSON_FILE); f.write(json); f.flush(); f.close(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:unl.cse.DataConvert.java
/** * <i>parsePersonsJson</i> will generate an JSON file using the parsed * data from the old system.// w w w . ja v a2 s . c o m * * @param jsonOut - If true, the JSON file will be displayed in the console */ private void parseInvoicesJson(boolean jsonOut) { System.out.println("Generating JSON file: " + INVOICES_JSON_FILE + "\n"); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting().disableHtmlEscaping(); Gson gson = gsonBuilder.create(); String json = gson.toJson(ihub); if (jsonOut == true) { System.out.println(json); } FileWriter f = null; try { f = new FileWriter(INVOICES_JSON_FILE); f.write(json); f.flush(); f.close(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:Util.SentenceUtil.java
public static void flushDataToJSON(ArrayList<JSONData> predictionData, String fileName, boolean predict) throws FileNotFoundException { final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(JSONData.class, new ILPSRLDataSerializer()); gsonBuilder.registerTypeAdapter(Sentence.class, new SentenceSerializer(predict)); gsonBuilder.registerTypeAdapter(ArgumentSpan.class, new ArgumentSpanSerializer()); gsonBuilder.setPrettyPrinting(); final Gson gson = gsonBuilder.create(); //final String json = gson.toJson(data); //gson.to//w ww . j a va 2 s . c o m String jsonString = gson.toJson(predictionData, new TypeToken<ArrayList<JSONData>>() { }.getType()); PrintWriter writer = new PrintWriter(fileName); writer.println(jsonString); writer.close(); }