List of usage examples for com.google.gson GsonBuilder setPrettyPrinting
public GsonBuilder setPrettyPrinting()
From source file:fr.bmartel.bboxapi.examples.request.Voip.java
License:Open Source License
public static void main(String[] args) { BboxApi api = new BboxApi(); String pass = ExampleUtils.getPassword(); api.setPassword(pass);// w w w . j a va 2 s. c o m VoipResponse voipResponse = api.getVoipData(); if (voipResponse.getStatus() == HttpStatus.OK) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.setPrettyPrinting().create(); Type listOfTestObject = new TypeToken<List<VoipEntry>>() { }.getType(); String voipList = gson.toJson(voipResponse.getVoipList(), listOfTestObject); LOGGER.debug(voipList); } else { LOGGER.error("http error : " + voipResponse.getStatus()); } }
From source file:fr.bmartel.bboxapi.examples.request.WanIp.java
License:Open Source License
public static void main(String[] args) { BboxApi api = new BboxApi(); WanIpResponse ipResponse = api.getIpInfo(); if (ipResponse.getStatus() == HttpStatus.OK) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.setPrettyPrinting().create(); Type listOfTestObject = new TypeToken<List<fr.bmartel.bboxapi.model.wan.WanIp>>() { }.getType();/*from w w w. j ava 2s .c o m*/ String ipInfo = gson.toJson(ipResponse.getWanIpResponse(), listOfTestObject); LOGGER.debug(ipInfo); } else { LOGGER.error("http error : " + ipResponse.getStatus()); } }
From source file:fr.bmartel.bboxapi.examples.request.WanXdsl.java
License:Open Source License
public static void main(String[] args) { BboxApi api = new BboxApi(); WanXdslResponse xdslResponse = api.getXdslInfo(); if (xdslResponse.getStatus() == HttpStatus.OK) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.setPrettyPrinting().create(); Type listOfTestObject = new TypeToken<List<WanItem>>() { }.getType();/*from w w w. j av a 2 s. c om*/ String xdslInfo = gson.toJson(xdslResponse.getWanXdslResponse(), listOfTestObject); LOGGER.debug(xdslInfo); } else { LOGGER.error("http error : " + xdslResponse.getStatus()); } }
From source file:fr.bmartel.bboxapi.examples.request.Wireless.java
License:Open Source License
public static void main(String[] args) { BboxApi api = new BboxApi(); String pass = ExampleUtils.getPassword(); api.setPassword(pass);/*from www . ja va 2 s. c o m*/ WirelessResponse wirelessResponse = api.getWirelessData(); if (wirelessResponse.getStatus() == HttpStatus.OK) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.setPrettyPrinting().create(); Type listOfTestObject = new TypeToken<List<WirelessItem>>() { }.getType(); String wireless = gson.toJson(wirelessResponse.getWirelessList(), listOfTestObject); LOGGER.debug(wireless); } else { LOGGER.error("http error : " + wirelessResponse.getStatus()); } }
From source file:fr.bmartel.bboxapi.examples.request.WirelessAclInfo.java
License:Open Source License
public static void main(String[] args) { BboxApi api = new BboxApi(); String pass = ExampleUtils.getPassword(); api.setPassword(pass);/*from ww w. j av a 2 s .com*/ WirelessAclResponse wirelessResponse = api.getWifiMacFilterInfo(); if (wirelessResponse.getStatus() == HttpStatus.OK) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.setPrettyPrinting().create(); Type listOfTestObject = new TypeToken<List<WirelessItem>>() { }.getType(); String wireless = gson.toJson(wirelessResponse.getAclResponse(), listOfTestObject); LOGGER.debug(wireless); } else { LOGGER.error("http error : " + wirelessResponse.getStatus()); } }
From source file:fr.itinerennes.api.client.gson.ItineRennesApiGsonFactory.java
License:Open Source License
public static Gson newInstance(final boolean prettyJson) { final GsonBuilder gb = new GsonBuilder(); gb.setDateFormat(DATE_FORMAT);//from w w w. ja v a 2 s. c o m gb.addSerializationExclusionStrategy(new ExcludeAnnotationStrategy()); gb.registerTypeAdapter(Time.class, new TimeTypeAdapter()); gb.registerTypeAdapter(Locale.class, new LocaleTypeAdapter()); gb.registerTypeAdapter(TimeZone.class, new TimeZoneTypeAdapter()); if (prettyJson) { gb.setPrettyPrinting(); } return gb.create(); }
From source file:gson.GsonManager.java
public static Gson createGsonBuilder(Map<Type, Object> compositeObjectAdapterMap, boolean isPrettyPrinting) { GsonBuilder gsonBuilder = new GsonBuilder(); if (isPrettyPrinting) { //===== Json Output is organized==== gsonBuilder.setPrettyPrinting(); //=================================== }//from ww w . j a v a 2 s . c o m // =============Adding Composite Objects to the Gson Builder================= if (compositeObjectAdapterMap != null) { compositeObjectAdapterMap .forEach((Type t, Object object) -> gsonBuilder.registerTypeAdapter(t, object)); } // =============Java 8 -> Lambda Expressions have been used================== Gson gson = gsonBuilder.create(); return gson; }
From source file:hd3gtv.mydmam.db.BackupDbElasticsearch.java
License:Open Source License
BackupDbElasticsearch(File outfile, String index_name, ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mapping, ImmutableOpenMap<String, Settings> settings) throws Exception { quotedprintablecodec = new QuotedPrintableCodec("UTF-8"); GsonBuilder g_builder = new GsonBuilder(); g_builder.disableHtmlEscaping();/* w w w .j av a 2s .c o m*/ if (BackupDb.mode_debug) { g_builder.setPrettyPrinting(); } gson = g_builder.create(); /** * Preparation */ fileoutputstream = new FileOutputStream(outfile); OutputFormat of = new OutputFormat(); of.setMethod("xml"); of.setEncoding("UTF-8"); of.setVersion("1.0"); of.setIndenting(BackupDb.mode_debug); if (BackupDb.mode_debug) { of.setIndent(2); } serializer = new XMLSerializer(fileoutputstream, of); content = serializer.asContentHandler(); content.startDocument(); /** * Headers */ AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "name", "CDATA", index_name); atts.addAttribute("", "", "created", "CDATA", String.valueOf(System.currentTimeMillis())); if (BackupDb.mode_debug) { atts.addAttribute("", "", "created_date", "CDATA", (new Date()).toString()); } content.startElement("", "", "index", atts); /** * Import configuration * ES Mapping */ String jo_mapping; ImmutableOpenMap<String, MappingMetaData> mapping_value; for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> mapping_cursor : mapping) { mapping_value = mapping_cursor.value; for (ObjectObjectCursor<String, MappingMetaData> mapping_value_cursor : mapping_value) { atts.clear(); atts.addAttribute("", "", "name", "CDATA", mapping_value_cursor.key); content.startElement("", "", "mapping", atts); jo_mapping = gson.toJson(mapping_value_cursor.value.getSourceAsMap()); if (BackupDb.mode_debug) { serializer.comment(jo_mapping); } jo_mapping = new String(quotedprintablecodec.encode(jo_mapping)); content.characters(jo_mapping.toCharArray(), 0, jo_mapping.length()); content.endElement("", "", "mapping"); } } /** * ES settings */ for (ObjectObjectCursor<String, Settings> settings_cursor : settings) { atts.clear(); content.startElement("", "", "settings", atts); jo_mapping = gson.toJson(settings_cursor.value.getAsMap()); if (BackupDb.mode_debug) { serializer.comment(jo_mapping); } jo_mapping = new String(quotedprintablecodec.encode(jo_mapping)); content.characters(jo_mapping.toCharArray(), 0, jo_mapping.length()); content.endElement("", "", "settings"); } }
From source file:ifsp.dsi.json.ProcessadorGson.java
public void gravar(Object obj) { GsonBuilder builder = new GsonBuilder(); Gson gson = builder.setPrettyPrinting().create(); String json = gson.toJson(obj); File file = new File(arquivo); Writer fileWriter = null;/*from w w w . j a v a 2 s . c om*/ Writer bufferWriter = null; try { fileWriter = new FileWriter(file); bufferWriter = new BufferedWriter(fileWriter); bufferWriter.write(json); } catch (IOException ex) { System.out.println(ex); } finally { fecharRecursos(bufferWriter); } }
From source file:io.hawkcd.http.GsonProvider.java
License:Apache License
public GsonProvider() { GsonBuilder builder = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization(); this.gson = builder.registerTypeAdapter(WsContractDto.class, new WsContractDeserializer()) .registerTypeAdapter(TaskDefinition.class, new TaskDefinitionAdapter()) .registerTypeAdapter(MaterialDefinition.class, new MaterialDefinitionAdapter()).create(); this.prettyGson = builder.setPrettyPrinting().create(); }